package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.exception.enums.BusExceptionEnum;
import cn.stylefeng.guns.sys.core.properties.GzhConfig;
import cn.stylefeng.guns.sys.core.util.DateUtil;
import cn.stylefeng.guns.sys.modular.system.entity.*;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.ProjectTaskEnum;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.ProjectTaskStatusEnum;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.RoleIdEnum;
import cn.stylefeng.guns.sys.modular.system.mapper.*;
import cn.stylefeng.guns.sys.modular.system.model.BtyBankyebDto;
import cn.stylefeng.guns.sys.modular.system.model.params.ProjectParam;
import cn.stylefeng.guns.sys.modular.system.model.params.TaskParam;
import cn.stylefeng.guns.sys.modular.system.model.result.ProjectResult;
import cn.stylefeng.guns.sys.modular.system.model.result.TaskResult;
import cn.stylefeng.guns.sys.modular.system.model.result.TaskStatusResult;
import cn.stylefeng.guns.sys.modular.system.service.*;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.io.Serializable;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jiangge
 * @since 2020-09-10
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {

    private static Logger logger = LoggerFactory.getLogger(ServiceImpl.class);

    @Resource
    private TaskMapper taskMapper;
    @Resource
    private TaskFlowMapper taskFlowMapper;
    @Resource
    private WeChatSendTempMsgService weChatSendTempMsgService;
    @Resource
    private ProjectMapper projectMapper;
    @Resource
    private ProjectService projectService;
    @Resource
    private TaskStatusMapper taskStatusMapper;
    @Resource
    private UserService userService;
    @Resource
    private BtyTxlService btyTxlService;
    @Resource
    private BtyRegionMapper regionMapper;
    @Resource
    private BtyTxlMapper btyTxlMapper;
    @Resource
    private BtyWxMapper btyWxMapper;
    @Resource
    private GcgMsgMapper msgMapper;
    @Resource
    private GzhConfig gzhConfig;
    @Resource
    private TaskStatusService taskStatusService;
    @Resource
    private UserMapper userMapper;
    @Autowired
    private BtyBrandMapper btyBrandMapper;
    @Resource
    private BtyDoubleCardService doubleCardService;

    // 跳转URL
    private String path = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=";
    //    private String path = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx373650bf8de7f27d&redirect_uri=";
//    private String path = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbb140a49393de65b&redirect_uri=";
    private String type = "&response_type=code";
    private String scope = "&scope=snsapi_userinfo";
    private String state = "&state=STATE#wechat_redirect";

    @Override
    public void add(TaskParam param) {
        Task entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaskParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaskParam param) {
        Task oldEntity = getOldEntity(param);
        Task newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaskResult findBySpec(TaskParam param) {
        return null;
    }

    @Override
    public List<TaskResult> findListBySpec(TaskParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaskParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaskParam param) {
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Task getOldEntity(TaskParam param) {
        return this.getById(getKey(param));
    }

    private Task getEntity(TaskParam param) {
        Task entity = new Task();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public List<Long> listIdsByRole(Long roleid) {
        return baseMapper.listIdsByRole(roleid);
    }

    /**
     * 状态表新增数据
     *
     * @param status
     */
    @Override
    public int insertRent(TaskStatus status, TaskFlow taskFlow) {

        //修改状态,所有修改操作数据库新增条数必须都大于0才会提交事务
        StringBuilder result = new StringBuilder();
        // 数据库修改条数
        int count = 0;

        //上传营业执照
        if (status.getTaskId() == 11) {
            //任务状态
            List<TaskStatus> taskStatuses = new ArrayList<>();
            //任务流水
            List<TaskFlow> taskFlows = new ArrayList<>();

            TaskStatus status1 = new TaskStatus();
            //可乐机报备
            status1.setTaskId(19);
            status1.setProId(status.getProId());
            status1.setStatus(0);
            status1.setTaskName("可乐机");
            status1.setContent("可乐机已报备");
            status1.setCreateId(status.getCreateId());

            taskStatuses.add(status);
            taskStatuses.add(status1);

            //流程明细表
            TaskFlow taskFlow1 = new TaskFlow();
            taskFlow1.setProId(status.getProId());
            taskFlow1.setTaskId(19);
            taskFlow1.setStatus(0);//1提交；2审核未通过；3审核通过
            taskFlow1.setTaskName("可乐机");
            taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
            taskFlow1.setCreateTime(new Date());

            taskFlows.add(taskFlow);
            taskFlows.add(taskFlow1);

            if (taskStatuses.size() != 0) {
                //新增信息
                count = taskMapper.addRentList(taskStatuses);
                result.append(count > 0 ? 1 : 0);
            }

            if (taskFlows.size() != 0) {
                //新增流程明细表
                count = taskFlowMapper.addList(taskFlows);
                result.append(count > 0 ? 1 : 0);
            }

            //通知可乐机负责人
            String now = DateUtil.getNow();//当前时间
            //查询店名
            String dm = taskMapper.selectDm(status.getProId());
            String data = dm + "应入可乐机";

            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机状态", "可乐机", now, data);

            Long role = 1314488482857709570L;//可乐机负责人
            List<String> openidlist = userService.listOpenidsByRole(role);

            if (ToolUtil.isNotEmpty(openidlist)){
                logger.info("=========可乐机负责人:" + openidlist + "========");

                String[] openids = openidlist.toArray(new String[openidlist.size()]);

                //推送消息
                weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
                logger.info("=======已推送可乐机负责人消息======");
            }

            //网上建店
        } else if (status.getTaskId() == 36 || status.getTaskId() == 37 || status.getTaskId() == 38) {

            //status表修改数据
            count = taskStatusMapper.updateStatus(status);
            result.append(count > 0 ? 1 : 0);
            //flow表新增数据
            count = taskFlowMapper.add(taskFlow);
            result.append(count > 0 ? 1 : 0);
            logger.info("========数据修改完成========");

            //通知督导
            String now = DateUtil.getNow();//当前时间
            //查询店名
            String dm = taskMapper.selectDm(status.getProId());
            String data = null;

            //审核通过
            if (status.getStatus() == 1) {
                data = dm + status.getContent();
            } else {
                data = dm + status.getTaskName() + "被驳回,原因如下:" + status.getContent();
            }

            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "网上建店状态", status.getTaskName(), now, data);

            Map<String, String> openidMap = projectService.selectDd(status.getProId());
            //督导
            String dd = openidMap.get("dd");

            String[] openids = new String[]{dd};

            //推送消息
            weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
            logger.info("=======已推送督导消息======");
        } else {

            count = taskMapper.addRent(status);
            result.append(count > 0 ? 1 : 0);
            count = taskFlowMapper.add(taskFlow);
            result.append(count > 0 ? 1 : 0);
        }


        if (result.indexOf("0") >= 0) {
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 督导工程部页面
     *
     * @param proId
     * @return
     */
    @Override
    public List<TaskStatus> taskList(Integer proId) {
//        //获取当前登陆者id
//        Long userId = LoginContextHolder.getContext().getUserId();
//        //获取当前登陆者角色id
//        String roleId = taskMapper.getRoleId(userId);

        //获取当前登陆者角色id
//        List<Long> roleList = LoginContextHolder.getContext().getUser().getRoleList();

//        return taskMapper.getList(roleList, proId);
        return taskMapper.taskList(proId);
    }

    /**
     * 根据店名查询ProID
     *
     * @param name
     * @return
     */
    @Override
    public int selectProId(String name) {
        return taskMapper.selectProId(name);
    }

    @Override
    public int selectCount(int proId, int taskId) {
        return taskMapper.select(proId, taskId);
    }

    /**
     * 流程进度
     *
     * @param param
     * @return
     */
    @Override
    public LayuiPageInfo productList(ProjectParam param) {
        if (ToolUtil.isNotEmpty(param.getTimeLimit())) {
            String[] split = param.getTimeLimit().split(" - ");
            param.setBeginTime(split[0]+" 00:00:00");
           String  endTime = split[1] + " 23:59:59";
           param.setEndTime(endTime);
        }
        Page pageContext = getPageContext();
        IPage page = projectMapper.getAllProPage(pageContext, param);
        //放入流程步骤数据
        setProcessSteps(page.getRecords());
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo yingYunQuery(ProjectParam param) {
        if (ToolUtil.isNotEmpty(param.getTimeLimit())) {
            String[] split = param.getTimeLimit().split(" - ");
            param.setBeginTime(split[0]+" 00:00:00");
            String  endTime = split[1] + " 23:59:59";
            param.setEndTime(endTime);
        }
        Page pageContext = getPageContext();
        IPage page = projectMapper.yingYunQuery(pageContext, param);
        //放入流程步骤数据
        setProcessSteps(page.getRecords());
        return LayuiPageFactory.createPageInfo(page);
    }


    /**
     * 获取流程步骤数据
     *
     * @param projectResultList
     */
    @Override
    public void setProcessSteps(List<ProjectResult> projectResultList) {
        if (CollectionUtil.isNotEmpty(projectResultList)) {
            //流程进度
            List<TaskStatusResult> list = taskStatusMapper.productList();
            if (CollectionUtil.isNotEmpty(list)) {
                //所有工程的督导完工
//                List<TaskStatus> duDaoTaskList = taskMapper.duDaoTaskList();
//                Map<Integer, List<TaskStatus>> duDaoTaskListMap = new HashMap<>();
//                if (CollectionUtil.isNotEmpty(duDaoTaskList)) {
//                    duDaoTaskListMap=duDaoTaskList.stream().collect(Collectors.groupingBy(TaskStatus::getProId));
//                }
                //遍历工程
                for (ProjectResult projectResult : projectResultList) {
                    //遍历流程
                    for (TaskStatusResult taskFlow : list) {
                        //是同一个工程
                        if (taskFlow.getProId().equals(projectResult.getId()) && ProjectTaskEnum.getByCode(taskFlow.getTaskId()) != null) {
                            switch (ProjectTaskEnum.getByCode(taskFlow.getTaskId())) {
                                //TODO-1开发区域经理确认
                                case TASK_62:
                                    projectResult.setKfqyjl((ProjectTaskStatusEnum.SUBMIT.getCode().equals(taskFlow.getStatus())) ? "开发区域经理已确认" : ((ProjectTaskStatusEnum.REJECT.getCode().equals(taskFlow.getStatus()))?"开发区域经理已驳回":""));
                                    projectResult.setKfqyjlName(taskFlow.getCreateName());
                                    break;
                                //TODO-1开发总监确认
                                case TASK_6:
                                    projectResult.setKfzj((ProjectTaskStatusEnum.SUBMIT.getCode().equals(taskFlow.getStatus())) ? "开发总监已确认" : ((ProjectTaskStatusEnum.REJECT.getCode().equals(taskFlow.getStatus()))?"开发总监已驳回":""));
                                    projectResult.setKfzjName(taskFlow.getCreateName());
                                    break;
                                //TODO-2工程总监确认
                                case TASK_5:
                                    projectResult.setGczj((ProjectTaskStatusEnum.SUBMIT.getCode().equals(taskFlow.getStatus())) ? "工程总监已确认" : ((ProjectTaskStatusEnum.REJECT.getCode().equals(taskFlow.getStatus())) ? "工程总监已驳回" : ""));
                                    projectResult.setGczjName(taskFlow.getCreateName());
                                    break;
                                //TODO-3营运总监确认
                                case TASK_7:
                                    projectResult.setYyzj((ProjectTaskStatusEnum.SUBMIT.getCode().equals(taskFlow.getStatus())) ? "营运总监已确认" : ((ProjectTaskStatusEnum.REJECT.getCode().equals(taskFlow.getStatus())) ? "营运总监已驳回" : ""));
                                    projectResult.setYyzjName(taskFlow.getCreateName());
                                    break;
                                //TODO-4营运总监指定营运经理
                                case TASK_40:
                                    if(taskFlow.getStatus()==1) {
                                        projectResult.setAllotYy("已指定营运经理");
                                    }
                                    break;
                                 //TODO 开发人员指定营运经理
                                case TASK_61:
                                    if(taskFlow.getStatus()==1) {
                                        projectResult.setAllotYy("已指定营运经理");
                                    }
                                    break;
                                //TODO-5营运经理指定督导
                                case TASK_41:
                                    if(taskFlow.getStatus()==1) {
                                     projectResult.setAllotDd("已指定督导");
                                    }
                                    break;
                                //TODO-7完工-有实际完工时间就算完工
                                case TASK_34:
                                    if (taskFlow.getContent() != null && !taskFlow.getContent().equals("")) {
                                        projectResult.setGcb("工程已完工");
                                    }

                                    //TODO-6督导确认完工
                                case TASK_11:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_11.getCode());
                                    break;
                                case TASK_13:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_13.getCode());
                                    break;
                                case TASK_15:
                                    if(taskFlow.getStatus()==2){
                                        this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_15.getCode());
                                    }
                                    break;
                                case TASK_16:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_16.getCode());
                                    break;
                                case TASK_17:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_17.getCode());
                                    break;
                                case TASK_18:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_18.getCode());
                                    break;
                                case TASK_19:
                                    if(taskFlow.getStatus()==1){
                                        this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_19.getCode());
                                    }
                                    break;
                                case TASK_21:
                                    if(taskFlow.getStatus()==2){
                                        this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_21.getCode());
                                    }
                                    break;
                                case TASK_22:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_22.getCode());
                                    break;
                                case TASK_23:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_23.getCode());
                                    break;
                                case TASK_36:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_36.getCode());
                                    break;
                                case TASK_37:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_37.getCode());
                                    break;
                                case TASK_38:
                                    this.setDudaoStatusList(projectResult, ProjectTaskEnum.TASK_38.getCode());
                                    break;
                                default:
                                    break;
                            }
                            //判断督导任务完成 11,13,15,16,17,18,19,21,22,23,36,37,38
                            List<Integer> dudaoStatusList = projectResult.getDudaoStatusList();
                            if(CollectionUtil.isNotEmpty(dudaoStatusList)){
                                if (dudaoStatusList.contains(ProjectTaskEnum.TASK_11.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_13.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_15.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_16.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_17.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_18.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_19.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_21.getCode())
                                        //&& dudaoStatusList.contains(ProjectTaskEnum.TASK_22.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_23.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_36.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_37.getCode())
                                        && dudaoStatusList.contains(ProjectTaskEnum.TASK_38.getCode())
                                ) {
                                    projectResult.setDudao("督导任务完成");
                                }
                            }
                        }
                    }
                    //TODO-6督导确认完工
//                    Integer dd = 0;
//                    if (CollectionUtil.isNotEmpty(duDaoTaskListMap) && duDaoTaskListMap.get(projectResult.getId()) != null) {
//                        dd = duDaoTaskListMap.get(projectResult.getId()).size();
//                    }
//                    if (dd != 24 && dd != 0) {
//                        projectResult.setDudao("督导任务未完成");
//                    }
                }

            }
        }
    }


    private void setDudaoStatusList(ProjectResult projectResult, Integer taskStatus) {
        if (CollectionUtil.isNotEmpty(projectResult.getDudaoStatusList())) {
            List<Integer> dudaoStatusList = projectResult.getDudaoStatusList();
            dudaoStatusList.add(taskStatus);
            projectResult.setDudaoStatusList(dudaoStatusList);
        } else {
            List<Integer> dudaoStatusList = new ArrayList<>();
            dudaoStatusList.add(taskStatus);
            projectResult.setDudaoStatusList(dudaoStatusList);
        }
    }


    /***
     * 督导未完成列表
     * @param proId
     * @return
     */
    @Override
    public List<Task> ddList(Integer proId) {
        return taskMapper.ddList(proId);
    }

    /**
     * 工程未完成列表
     *
     * @param proId
     * @return
     */
    @Override
    public List<Task> ggList(Integer proId) {
        return taskMapper.ggList(proId);
    }

    /**
     * 督导确认完工
     *
     * @param proId
     * @param taskId
     * @return
     */
    @Override
    public int endSave(Integer proId, Integer taskId) {
        //判断是否已经存在此数据
        int num = taskMapper.getRent(proId, taskId);
        if (num == 0) {
            //状态表实体
            TaskStatus status = new TaskStatus();
            status.setProId(proId);
            status.setTaskId(taskId);
            status.setStatus(1);
            status.setTaskName("督导确认完工");

            //流程明细表
            TaskFlow taskFlow = new TaskFlow();
            taskFlow.setProId(status.getProId());
            taskFlow.setTaskId(status.getTaskId());
            taskFlow.setStatus(1);//1提交；2审核未通过；3审核通过
            taskFlow.setTaskName("督导确认完工");
            taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
            taskFlow.setCreateTime(new Date());

            insertRent(status, taskFlow);
            return 1;//添加成功
        } else {
            return 0;//督导已确认完工
        }
    }


    /**
     * 新增任务信息
     *
     * @param taskStatus
     * @return
     * @throws ParseException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData addRent(List<TaskStatus> taskStatus) throws ParseException {

        //修改状态,所有修改操作数据库新增条数必须都大于0才会提交事务
        StringBuilder result = new StringBuilder();
        // 数据库修改条数
        int count = 0;

        if (ToolUtil.isNotEmpty(taskStatus)) {

            //任务状态
            List<TaskStatus> taskStatuses = new ArrayList<>();
            //任务流水
            List<TaskFlow> taskFlows = new ArrayList<>();

            for (TaskStatus status : taskStatus) {

                //填写内容为固定项
                if (status.getTaskId() != null) {

                    //查询该工程该项是否已经填写信息
                    int msg = taskMapper.getRent(status.getProId(), status.getTaskId());
                      if(msg!=0){
                          //营业执照名称
                          if(status.getTaskId() == 56 && ToolUtil.isNotEmpty(status.getContent())){
                              //获取妖码
                              String yaoma = projectMapper.getYm(status.getProId());
                              if(ToolUtil.isNotEmpty(yaoma)){
                                  BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                  if(ToolUtil.isNotEmpty(txl)){
                                      txl.setYyzzmc(status.getContent());
                                      btyTxlService.updateById(txl);
                                  }
                              }

                          }
                          //统一社会信用代码
                          else if(status.getTaskId() == 57 && ToolUtil.isNotEmpty(status.getContent())){
                              //获取妖码
                              String yaoma = projectMapper.getYm(status.getProId());
                              if(ToolUtil.isNotEmpty(yaoma)){
                                  BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                  if(ToolUtil.isNotEmpty(txl)){
                                      txl.setShxydm(status.getContent());
                                      btyTxlService.updateById(txl);
                                  }
                              }
                          }

                          //法人姓名 更新到双证审核中
                          else if(status.getTaskId() == 59 && ToolUtil.isNotEmpty(status.getContent())){
                              BtyDoubleCard doubleCard=doubleCardService.getOne(new QueryWrapper<BtyDoubleCard>().eq("pro_id",status.getProId()));
                              if(ToolUtil.isNotEmpty(doubleCard)){
                                  doubleCard.setFrxm(status.getContent());
                                  doubleCardService.updateById(doubleCard);
                              }
                          }
                      }
                    //之前没有填写过信息
                    if (msg == 0) {

                        //查询店名
                        String dm = taskMapper.selectDm(status.getProId());

                        if (status.getStatus() == null) {
                            status.setStatus(1);//提交信息
                        }
                        status.setCreateId(LoginContextHolder.getContext().getUserId());

                        //不是可乐机, 不是出图日期新增,不是到货日期
                        if (status.getTaskId() != 19 && status.getTaskId() != 15) {
//                            && status.getTaskId() != 31
                            taskStatuses.add(status);


                            //是可乐机修改状态
                        }
                        else if (status.getTaskId() == 19) {
                            taskMapper.updateStatus(status);

                            //通知督导
                            String now = DateUtil.getNow();//当前时间
                            String data = dm + "可乐机已确认";
                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机已确认", "可乐机已确认", now, data);

                            //推送督导可乐机已确认消息
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());
                            //督导
                            String dd = openidMap.get("dd");
                            //督导id
                            User user = btyWxMapper.selectUser(dd);
                            String[] openid = new String[]{user.getOpenid()};

                            //可乐机url（督导）
                            String kljUrl = BusConst.KLJDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kljUrl) + type + scope + state;

                            //推送督导消息
                            weChatSendTempMsgService.sendmsg(openid, url, tempObj);
                            logger.info("======已推送督导可乐机已确认消息======");

                            //消息表中新增可乐机消息
                            GcgMsg gcgMsg = new GcgMsg();
                            gcgMsg.setBusinessId(status.getProId());//业务id
                            gcgMsg.setBusinessType("工程");//业务类型
                            gcgMsg.setBusinessName(dm);//业务名称
                            gcgMsg.setTaskId(status.getTaskId());//任务id
                            gcgMsg.setMsgType("可乐机已确认");//消息类型
                            gcgMsg.setMessage(data);//消息内容
                            gcgMsg.setPath(url);//跳转路径
                            gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                            gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                            gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                            gcgMsg.setCreateTime(new Date());//创建时间

                            //消息表新增可乐机已确认消息
                            msgMapper.insert(gcgMsg);


                        }






                        //出图日期修改状态
//                        else if (status.getTaskId() == 31){
//                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//                            Date date = new Date();
//                            String format = sdf.format(date);
//                            status.setContent(format);//出图日期改为确定日期
//                            taskMapper.updateStatus(status);
//                        }

//                        taskStatuses.add(status);


                        //流程明细表
                        TaskFlow taskFlow = new TaskFlow();
                        taskFlow.setProId(status.getProId());
                        taskFlow.setTaskId(status.getTaskId());

                        if (status.getTaskName() != null || status.getTaskName() != "") {
                            taskFlow.setTaskName(status.getTaskName());
                        }
                        taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                        taskFlow.setCreateTime(new Date());

                        //不是到货日期
                        if (status.getTaskId() != 15){
                            if (status.getStatus() != null) {
                                taskFlow.setStatus(status.getStatus());
                            } else {
                                taskFlow.setStatus(1);
                            }
                            //到货日期
                        }else {
                            taskFlow.setStatus(0);
                        }

                        taskFlows.add(taskFlow);

                        //开工日期
                        if (status.getTaskId() == 32) {

//                            TaskStatus status1 = new TaskStatus();
//                            //预估完工日期
//                            status1.setTaskId(33);
//                            //开工日期+28天
//                            status1.setContent(DateUtil.addDate(status.getContent(), 28));
//                            status1.setProId(status.getProId());
//                            status1.setStatus(1);
//                            status1.setTaskName("预估完工日期");
//
//                            taskStatuses.add(status1);
//
//                            //流程明细表
//                            TaskFlow taskFlow1 = new TaskFlow();
//                            taskFlow1.setProId(status.getProId());
//                            taskFlow1.setTaskId(33);
//                            taskFlow1.setStatus(1);//1提交；0审核未通过
//                            taskFlow1.setTaskName("预估完工日期");
//                            taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
//                            taskFlow1.setCreateTime(new Date());
//
//                            taskFlows.add(taskFlow1);

                            //刘书伟
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data = dm + "已确定开工日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;

                            logger.info("开工日期已确认=========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            //推送营运经理,督导工程开工消息
                            String data1 = dm + "已确定开工日期为:" + status.getContent() + ",请及时推进工作";
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "开工日期已确定", "开工日期已确定", DateUtil.getNow(), data1);
                            //查询工程督导,营运经理openID
                            Map<String, String> map = projectService.selectDd(status.getProId());
                            String dd = map.get("dd");
                            String yyjl = map.get("yyjl");

                            if (dd != null && yyjl != null) {
                                List<String> list = new ArrayList<>();
                                list.add(dd);
                                list.remove(yyjl);
                                list.add(yyjl);

                                //督导营运经理id
                                List<User> userList = btyWxMapper.getUser(list);
                                if (ToolUtil.isNotEmpty(userList)) {
                                    for (User user1 : userList) {
                                        //本店任务页面url
                                        String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                        String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;
                                        String[] openid = new String[]{user1.getOpenid()};

                                        //推送消息（本店任务页面）
                                        weChatSendTempMsgService.sendmsg(openid, url1, tempObj1);
                                        logger.info("=======推送督导,营运经理消息==========");

                                        //消息表中新增工程开工消息
                                        GcgMsg gcgMsg2 = new GcgMsg();
                                        gcgMsg2.setBusinessId(status.getProId());//业务id
                                        gcgMsg2.setBusinessType("工程");//业务类型
                                        gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                        gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                        gcgMsg2.setMessage(data1);//消息内容
                                        gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                        gcgMsg2.setPath(url1);//跳转路径
                                        gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                        gcgMsg2.setCreateTime(new Date());//创建时间

                                        //消息表新增工程开工消息
                                        msgMapper.insert(gcgMsg2);

                                    }
                                }

                            } else if (yyjl != null) {
                                //营运经理id
                                User user1 = btyWxMapper.selectUser(yyjl);
                                //本店任务页面url
                                String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;

                                String[] yyjlOpenid = new String[]{yyjl};
                                //推送消息（本店任务页面）
                                weChatSendTempMsgService.sendmsg(yyjlOpenid, url1, tempObj1);
                                logger.info("=======推送营运经理消息==========");

                                //消息表中新增工程开工消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                gcgMsg2.setPath(url1);//跳转路径
                                gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增工程开工消息
                                msgMapper.insert(gcgMsg2);

                            } else if (dd != null) {
                                //督导id
                                User user1 = btyWxMapper.selectUser(dd);
                                //本店任务页面url
                                String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;

                                String[] ddOpenid = new String[]{dd};
                                //推送消息（本店任务页面）
                                weChatSendTempMsgService.sendmsg(ddOpenid, url1, tempObj1);
                                logger.info("=======推送督导消息==========");

                                //消息表中新增工程开工消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                gcgMsg2.setPath(url1);//跳转路径
                                gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增工程开工消息
                                msgMapper.insert(gcgMsg2);

                            } else {
                                logger.info("=======该工程暂无督导和营运经理==========");
                            }

                            //人事部
                            Long role = 1277443924781469698L;//人事部
                            List<String> openidlist = userService.listOpenidsByRole(role);
                            String[] rsOpenids = openidlist.toArray(new String[openidlist.size()]);
                            if (ToolUtil.isNotEmpty(rsOpenids)){
                                //推送人事部消息
                                String rsData = dm + "已确定开工日期为:" + status.getContent() + ",需要建档案。该店督导为：" + ddName + "电话为:" + ddTel;
                                logger.info("开工日期已确认=========");
                                JSONObject rsTempObj = weChatSendTempMsgService.setTempParam(dm, null, "建档案", "建档案", DateUtil.getNow(), rsData);
                                //推送消息
                                weChatSendTempMsgService.sendmsg(rsOpenids, BusConst.MSURL, rsTempObj);

                                logger.info("=======推送消息给人事部==========");
                            }


                            //将门店同步到brand表
                            addBrand(status.getProId());
                            //预估完工日期
                        } else if (status.getTaskId() == 33) {

                            TaskStatus status1 = new TaskStatus();
                            //预估开业时间
                            status1.setTaskId(22);
                            //预估完工日期+7天
                            status1.setContent(DateUtil.addDate(status.getContent(), 7));
                            status1.setProId(status.getProId());
                            status1.setStatus(1);
                            status1.setTaskName("预估开业时间");
                            status1.setCreateId(LoginContextHolder.getContext().getUserId());

                            taskStatuses.add(status1);

                            //流程明细表
                            TaskFlow taskFlow1 = new TaskFlow();
                            taskFlow1.setProId(status.getProId());
                            taskFlow1.setTaskId(22);
                            taskFlow1.setStatus(1);//1提交；0审核未通过
                            taskFlow1.setTaskName("预估开业时间");
                            taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
                            taskFlow1.setCreateTime(new Date());

                            taskFlows.add(taskFlow1);

//                            //推送收银系统确认消息
//                            String data = dm + "已确定预计开业日期为:" + status1.getContent() + ",请确认收银系统";
//                            logger.info("==========预计开业时间已确认========");
//
//                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);
//                            //收银系统负责人(刘书伟)
////                            String syxt = BusConst.LSW;
//                            String syxt = "oJnvX6V-i1H8JV24PMPzhiZ1Qzn0";
//                            String[] openids = new String[]{syxt};
//
//                            //收银系统负责人 (刘书伟)id
//                            User user = btyWxMapper.selectUser(syxt);
//
//                            //收银系统url（负责人）
//                            String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&proName=" + dm + "&userId=" + user.getUserId();
//                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;
//                            //String url = path + URLEncoder.encode(syUrl) + type + scope + state;
//
//                            //推送收银系统消息
////                            weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
//                            weChatSendTempMsgService.sendmsg(openids, url, tempObj);
//                            logger.info("=======推送收银系统负责人消息==========");
//
//
//                            //消息表中新增收银系统消息
//                            GcgMsg gcgMsg = new GcgMsg();
//                            gcgMsg.setBusinessId(status.getProId());//业务id
//                            gcgMsg.setBusinessType("工程");//业务类型
//                            gcgMsg.setBusinessName(dm);//业务名称
//                            gcgMsg.setTaskId(21);//任务id
//                            gcgMsg.setMsgType("确认收银系统提醒");//消息类型
//                            gcgMsg.setMessage(data);//消息内容
//                            gcgMsg.setPath(url);//跳转路径
//                            gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
//                            gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
//                            gcgMsg.setReceiveUser(user.getUserId());//接收人ID
//                            gcgMsg.setCreateTime(new Date());//创建时间
//
//                            //消息表新增收银系统数据
//                            msgMapper.insert(gcgMsg);
                        }

                        //确定工程开业日期
                        else if (status.getTaskId() == 16) {

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            Date toDate = sdf.parse(status.getContent());//开业日期

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setOpenDate(toDate);//开业日期
                            projectParam.setId(status.getProId());

                            //修改工程开业时间
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已添加开业时间========");

                            //收银系统负责人 (刘书伟)
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data = dm + "已确定开业日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;
                            logger.info("==========开业时间已确认========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            String data1 = dm + "已确定开业日期:" + status.getContent() + "。该店督导为：" + ddName + "电话为:" + ddTel;
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认开业日期", "开业日期", DateUtil.getNow(), data1);

                            //设计总监(朱小平)
                            String sjzj = BusConst.SJZJ;
                            String[] openids1 = new String[]{sjzj};


                            //设计总监(朱小平)id
                            User user1 = btyWxMapper.selectUser(sjzj);

                            if (ToolUtil.isNotEmpty(user1)){
                                //确定开业日期url（已确认）
                                String kyUrl = BusConst.KYURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kyUrl) + type + scope + state;

                                //推送设计总监消息
                                weChatSendTempMsgService.sendmsg(openids1, url1, tempObj1);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(status.getTaskId());//任务id
                                gcgMsg1.setMsgType("已确认开业日期提醒");//消息类型
                                gcgMsg1.setMessage(data1);//消息内容
                                gcgMsg1.setPath(url1);//跳转路径
                                gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg1.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg1);
                            }

                            //丁玲
                            String dl = BusConst.DL;
                            String[] openid = new String[]{dl};
                            //丁玲id
                            User userDl = btyWxMapper.selectUser(dl);

                            if (ToolUtil.isNotEmpty(userDl)){
                                //推送丁玲消息
                                weChatSendTempMsgService.sendmsg(openid, BusConst.MSURL, tempObj1);
                                logger.info("=======推送丁玲消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
                                gcgMsg2.setTaskId(status.getTaskId());//任务id
                                gcgMsg2.setMsgType("已确认开业日期提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setPath(BusConst.MSURL);//跳转路径
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg2.setReceiveUser(userDl.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg2);
                            }

                            //确认收银系统
                        } else if (status.getTaskId() == 21) {

                            if (status.getContent().equals("收银账号已建完，收银档案未建完")) {

                                addTxl(status.getProId(), null, status.getTaskId());


//                                //查询该工程的城市,营运经理,开业时间
//                                Project project = projectMapper.selectProject(status.getProId());
//
//                                if (ToolUtil.isNotEmpty(project)) {
//
//                                    String btyDm = project.getName();
//                                    //店名（截取省之后的字符）
//                                    if (btyDm.contains("省") || btyDm.contains("自治区")){
//                                        if (!project.getProvinceName().equals("北京") && !project.getProvinceName().equals("天津")
//                                                && !project.getProvinceName().equals("上海") && !project.getProvinceName().equals("重庆")) {
//
//                                            btyDm = project.getName().split(project.getProvinceName())[1].replaceAll("\\s*", "");
//                                        }
//                                    }
//
//                                    //通讯录新增数据
//                                    BtyTxl btyTxl = new BtyTxl();
//                                    btyTxl.setCsqy(project.getProvinceName());//城市区域
//                                    btyTxl.setYyjlqy(project.getYyjlName());//营运经理
//                                    btyTxl.setDm(btyDm);//店名
//                                    btyTxl.setKysj(project.getOpenTime());//开业时间
//                                    btyTxl.setCtdz(project.getRestAddress());//餐厅地址
//                                    btyTxl.setYytel(project.getYyjlTel());//营运经理电话
//                                    btyTxlService.addct(btyTxl);
//
//
//                                    //查询表中是否存在该数据
//                                    int ddCount = btyTxlMapper.selectCount(btyDm, "督导");
//
//                                    //bty_txl_ry表新增数据
//                                    BtyTxlRY btyTxlRY = new BtyTxlRY();
//                                    btyTxlRY.setZw("督导");//职务(督导)
//                                    btyTxlRY.setFzr(project.getDdName());//负责人
//                                    btyTxlRY.setLxfs(project.getDdTel());//联系方式
//                                    btyTxlRY.setSsctdm(btyDm);//店名
//
//                                    //不存在该数据
//                                    if (ddCount == 0) {
//                                        btyTxlMapper.addfzr(btyTxlRY);
//                                    } else {
//                                        btyTxlMapper.updateTxlRY(btyTxlRY);
//                                    }
//
//                                    //查询表中是否存在该数据
//                                    int dzCount = btyTxlMapper.selectCount(btyDm, "店长");
//
//                                    //bty_txl_ry表新增数据
//                                    BtyTxlRY btyTxlRY1 = new BtyTxlRY();
//                                    btyTxlRY1.setZw("店长");//职务(店长)
//                                    btyTxlRY1.setFzr(project.getDz());//负责人
//                                    btyTxlRY1.setLxfs(project.getDzTel());//联系方式
//                                    btyTxlRY1.setSsctdm(btyDm);//店名
//
//                                    //不存在该数据
//                                    if (dzCount == 0) {
//                                        btyTxlMapper.addfzr(btyTxlRY1);
//                                    } else {
//                                        btyTxlMapper.updateTxlRY(btyTxlRY1);
//                                    }
//
//                                    //btyy_region表新增数据
//                                    BtyRegion btyRegion = new BtyRegion();
//                                    btyRegion.setYyjl(project.getYyjlName());//营运经理
//                                    btyRegion.setDm(btyDm);//店名
//                                    btyRegion.setDd(project.getDdName());//督导
//                                    btyRegion.setDz(project.getDz());//店长
//                                    btyRegion.setCreateTime(new Date());
//                                    this.regionMapper.insert(btyRegion);
//                                }


                                //通知督导,韩铭渲
                                String now = DateUtil.getNow();//当前时间
                                String data = dm + "收银账号已建完";

                                JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);

                                Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                //督导
                                String dd = openidMap.get("dd");

                                List list = new ArrayList();
                                list.add(dd);

                                //接收消息人id
                                List<User> userList = btyWxMapper.getUser(list);
                                if (ToolUtil.isNotEmpty(userList)) {
                                    for (User user : userList) {

                                        //收银系统url(督导)
                                        String syUrl = BusConst.SYDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                                        String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                        String[] openids = new String[]{user.getOpenid()};

                                        //推送消息
                                        weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                        logger.info("======已推送督导收银账号已建完消息======");


                                        //消息表中新增收银系统消息
                                        GcgMsg gcgMsg1 = new GcgMsg();
                                        gcgMsg1.setBusinessId(status.getProId());//业务id
                                        gcgMsg1.setBusinessType("工程");//业务类型
                                        gcgMsg1.setBusinessName(dm);//业务名称
                                        gcgMsg1.setTaskId(status.getTaskId());//任务id
                                        gcgMsg1.setMsgType("收银账号已建完");//消息类型
                                        gcgMsg1.setMessage(data);//消息内容
                                        gcgMsg1.setPath(url);//跳转路径
                                        gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                        gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                        gcgMsg1.setCreateTime(new Date());//创建时间

                                        //消息表新增收银系统消息
                                        msgMapper.insert(gcgMsg1);
                                    }
                                }

                                //收银档案负责人（韩铭渲）
                                String sy = BusConst.HMX;
                                String[] openid = new String[]{sy};
                                User user1 = btyWxMapper.selectUser(sy);

                                if (ToolUtil.isNotEmpty(user1)){
                                    //收银档案负责人url
                                    String syUrl = BusConst.DAURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                    String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                    //推送收银档案负责人消息
                                    weChatSendTempMsgService.sendmsg(openid, url1, tempObj);
                                    logger.info("======已推送收银档案负责人收银账号已建完消息======");

                                    //消息表中新增收银系统消息
                                    GcgMsg gcgMsg2 = new GcgMsg();
                                    gcgMsg2.setBusinessId(status.getProId());//业务id
                                    gcgMsg2.setBusinessType("工程");//业务类型
                                    gcgMsg2.setBusinessName(dm);//业务名称
                                    gcgMsg2.setTaskId(status.getTaskId());//任务id
                                    gcgMsg2.setMsgType("收银账号已建完");//消息类型
                                    gcgMsg2.setMessage(data);//消息内容
                                    gcgMsg2.setPath(url1);//跳转路径
                                    gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                    gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                    gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                    gcgMsg2.setCreateTime(new Date());//创建时间

                                    //消息表新增收银系统消息
                                    msgMapper.insert(gcgMsg2);
                                }
                            }

                        }
                        //卫生许可证
                        else if (status.getTaskId() == 44) {

                            addTxl(status.getProId(), status.getContent(), status.getTaskId());

//                            //获取妖码
//                            String yaoma = projectMapper.getYm(status.getProId());
//
//                            //通讯录同步食品经营许可证数据
//                            BtyTxl btyTxl = new BtyTxl();
//                            btyTxl.setSpjyxk(status.getContent());//食品经营许可证
//                            btyTxl.setCtbh(yaoma);//妖码
//                            btyTxlService.edit(btyTxl);
                        }

//                        //预计开业时间
//                        else if (status.getTaskId() == 22) {
//
//                            //推送收银系统确认消息
//                            //查询店名
//                            String dm = taskMapper.selectDm(status.getProId());
//                            String data = dm + "已确定预计开业日期为:" + status.getContent() + ",请确认收银系统";
//                            logger.info("==========预计开业时间已确认========");
//
//                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);
//                            //收银系统负责人(刘书伟)
//                            String[] openids = new String[]{BusConst.LSW};
//                            //推送收银系统消息
//                            weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
//                            logger.info("===========推送收银系统负责人消息==========");
//
//                        }
                        //上传营业执照
                        else if (status.getTaskId() == 11) {

                            TaskStatus status1 = new TaskStatus();
                            //可乐机报备
                            status1.setTaskId(19);
                            status1.setProId(status.getProId());
                            status1.setStatus(0);
                            status1.setTaskName("可乐机");
                            status1.setContent("可乐机已报备");
                            status1.setCreateId(LoginContextHolder.getContext().getUserId());

                            taskStatuses.add(status1);

                            //流程明细表
                            TaskFlow taskFlow1 = new TaskFlow();
                            taskFlow1.setProId(status.getProId());
                            taskFlow1.setTaskId(19);
                            taskFlow1.setStatus(0);//1提交；2审核未通过；3审核通过
                            taskFlow1.setTaskName("可乐机");
                            taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
                            taskFlow1.setCreateTime(new Date());

                            taskFlows.add(taskFlow1);

                            //通知可乐机负责人
                            String now = DateUtil.getNow();//当前时间
                            String data = dm + "应入可乐机";

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机状态", "可乐机", now, data);

                            Long role = 1314488482857709570L;//可乐机负责人
                            List<String> openidlist = userService.listOpenidsByRole(role);

                            if (ToolUtil.isNotEmpty(openidlist)){
                                logger.info("=========可乐机负责人:" + openidlist + "========");
                                //可乐机负责人id
                                List<User> user1 = btyWxMapper.getUser(openidlist);

                                if (ToolUtil.isNotEmpty(user1)) {
                                    for (User user : user1) {

                                        //可乐机url
                                        String kljUrl = BusConst.KLJURL + "&proId=" + status.getProId() + "&taskId=19" + "&userId=" + user.getUserId();
                                        String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kljUrl) + type + scope + state;

                                        String[] openids = new String[]{user.getOpenid()};

                                        //推送消息
                                        weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                        logger.info("======已推送可乐机负责人消息======");


                                        //消息表中新增应入可乐机消息
                                        GcgMsg gcgMsg = new GcgMsg();
                                        gcgMsg.setBusinessId(status.getProId());//业务id
                                        gcgMsg.setBusinessType("工程");//业务类型
                                        gcgMsg.setBusinessName(dm);//业务名称
                                        gcgMsg.setTaskId(19);//任务id
                                        gcgMsg.setMsgType("应入可乐机提醒");//消息类型
                                        gcgMsg.setMessage(data);//消息内容
                                        gcgMsg.setPath(url);//跳转路径
                                        gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                        gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                        gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                        gcgMsg.setCreateTime(new Date());//创建时间

                                        //消息表新增可乐机消息
                                        msgMapper.insert(gcgMsg);
                                    }
                                }
                            }

                            //刘书伟
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};
                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data1 = dm + "已填写营业执照信息，请确认收银系统。该店督导为：" + ddName + "电话为: " + ddTel;
                            logger.info("==========已填写营业执照信息========");

                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data1);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url(负责人)
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj1);
                                logger.info("===========推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(21);//任务id
                                gcgMsg1.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg1.setMessage(data);//消息内容
                                gcgMsg1.setPath(url);//跳转路径
                                gcgMsg1.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg1);
                            }

                            //配送要货完成
                        } else if (status.getTaskId() == 15) {

                            status.setStatus(0);//待发货
                            taskStatuses.add(status);

                            // 工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setArrivalTime(status.getContent());//到货日期
                            projectParam.setId(status.getProId());
                            projectParam.setPsStatus("0");//待发货

                            //修改工程到货日期
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已添加到货日期========");


                            //推送供应链消息
                            String data = dm + "已确认到货日期为" + status.getContent() + "，请尽快完成配送！";
                            logger.info("==========已完成配送========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "配送要货", "配送要货", DateUtil.getNow(), data);

//                            Long role = 1314441729702100993L;//供应链
                            Long role = 1278615893124055041L;//配送管理
                            List<String> list = userService.listOpenidsByRole(role);

                            if (ToolUtil.isNotEmpty(list)){
                                logger.info("=========配送管理:" + list + "========");
                                String[] openids = list.toArray(new String[list.size()]);
                                //推送消息
                                weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
                                logger.info("======推送配送管理消息======");
                            }



//                            //配送管理id
//                            List<User> user1 = btyWxMapper.getUser(list);
//
//                            if (ToolUtil.isNotEmpty(user1)) {
//                                for (User user : user1) {
//
//                                    //配送要货url
//                                    String psyhUrl = BusConst.PSYHURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
//                                    String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(psyhUrl) + type + scope + state;
//
//                                    String[] openids = new String[]{user.getOpenid()};
//
//                                    //推送消息
//                                    weChatSendTempMsgService.sendmsg(openids, url, tempObj);
//                                    logger.info("======推送配送管理消息======");
//
//
//                                    //消息表中新增配送要货完成消息
//                                    GcgMsg gcgMsg = new GcgMsg();
//                                    gcgMsg.setBusinessId(status.getProId());//业务id
//                                    gcgMsg.setBusinessType("工程");//业务类型
//                                    gcgMsg.setBusinessName(dm);//业务名称
//                                    gcgMsg.setTaskId(status.getTaskId());//任务id
//                                    gcgMsg.setMsgType("推送配送管理消息");//消息类型
//                                    gcgMsg.setMessage(data);//消息内容
//                                    gcgMsg.setPath(url);//跳转路径
//                                    gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
//                                    gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
//                                    gcgMsg.setReceiveUser(user.getUserId());//接收人ID
//                                    gcgMsg.setCreateTime(new Date());//创建时间
//
//                                    //消息表新增配送要货完成消息
//                                    msgMapper.insert(gcgMsg);
//                                }
//                            }

                        }




                        //之前填写过该项,修改数据
                    } else {

                        //流程明细表
                        TaskFlow taskFlow = new TaskFlow();

                        //修改预估完工日期
                        if (status.getTaskId() == 33) {

                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(33);
                            taskFlow.setStatus(1);//1提交；0审核未通过
                            taskFlow.setTaskName("预估完工日期");
                            taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                            taskFlow.setCreateTime(new Date());

                            //判断是否因为逾期修改预估完工日期
                            if (ToolUtil.isNotEmpty(status.getNote())) {

                                Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                //督导
                                String dd = openidMap.get("dd");
                                //营运经理
                                String yyjl = openidMap.get("yyjl");
                                Long role_yyzj = 1305422678196678657L;//营运总监
                                List<String> openidlist = userService.listOpenidsByRole(role_yyzj);
                                if (ToolUtil.isEmpty(openidlist)) {
                                    logger.error("未找到营运总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========营运总监:" + openidlist + "========");

                                Long role_gczj = 1305422420779659266L;//工程总监
                                List<String> gclist = userService.listOpenidsByRole(role_gczj);
                                if (ToolUtil.isEmpty(gclist)) {
                                    logger.error("未找到工程总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========工程总监:" + gclist + "========");

                                Long role_kfzj = 1305422111420379138L;//开发总监
                                List<String> kflist = userService.listOpenidsByRole(role_kfzj);
                                if (ToolUtil.isEmpty(kflist)) {
                                    logger.error("未找到开发总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========开发总监:" + kflist + "========");

                                openidlist.remove(dd);
                                openidlist.add(dd);
                                openidlist.remove(yyjl);
                                openidlist.add(yyjl);
                                openidlist.removeAll(gclist);
                                openidlist.addAll(gclist);
                                openidlist.removeAll(kflist);
                                openidlist.addAll(kflist);

                                String[] openids = openidlist.toArray(new String[openidlist.size()]);

                                //查询店名
                                String dm = taskMapper.selectDm(status.getProId());

                                //查询开工时间
                                String con = taskMapper.selectCon(status.getProId(), 32).getContent();
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                                String dateSdf = sdf.format(new Date());//当前日期
                                Date date1 = null;
                                Date d1 = null;
                                long diffDays = 0;
                                Date wg = null;
                                long wgDays = 0;

                                try {
                                    date1 = sdf.parse(dateSdf);//当前日期
                                    d1 = sdf.parse(con);//开工时间
                                    String s = DateUtil.addDate(con, 28);//开工时间+28天(应该完工日期)
                                    wg = sdf.parse(s);

                                    //毫秒ms
                                    long diff = date1.getTime() - d1.getTime();//已开工时间
                                    diffDays = diff / (24 * 60 * 60 * 1000);//计算两个日期相差的时间

                                    //毫秒ms
                                    long diff1 = date1.getTime() - wg.getTime();//逾期时间
                                    wgDays = diff1 / (24 * 60 * 60 * 1000);//计算两个日期相差的时间
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }

//                                String data = dm + "已开工" + diffDays + "天,逾期" + wgDays + "天,逾期原因：" + status.getNote();
//                                JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "工程逾期", "工程逾期", DateUtil.getNow(), data);
//
//                                //推送消息
//                                weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
//                                logger.info("==========推送消息给督导,营运经理,营运总监,工程总监,开发总监=======");
                            }

                        } else
                            //确认收银系统
                            if (status.getTaskId() == 21) {
                                if (status.getContent() == "收银账号已建完，收银档案未建完") {

                                    //通知督导,设计
                                    String now = DateUtil.getNow();//当前时间
                                    //查询店名
                                    String dm = taskMapper.selectDm(status.getProId());
                                    String data = dm + "收银账号已建完";

                                    JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);

                                    Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                    //督导
                                    String dd = openidMap.get("dd");
                                    //设计(任召栋)
                                    String sj = BusConst.SJ;
                                    //设计(任召栋)
                                    String[] openid = new String[]{sj};


                                    //设计(任召栋)
                                    User user1 = btyWxMapper.selectUser(sj);

                                    if (ToolUtil.isNotEmpty(user1)){
                                        //收银系统url（设计）
                                        String sjUrl = BusConst.SYSJURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                        String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(sjUrl) + type + scope + state;
                                        //推送设计消息
                                        weChatSendTempMsgService.sendmsg(openid, url1, tempObj);
                                        logger.info("======已推送督导收银账号已建完消息======");

                                        //消息表中新增收银系统消息
                                        GcgMsg gcgMsg = new GcgMsg();
                                        gcgMsg.setBusinessId(status.getProId());//业务id
                                        gcgMsg.setBusinessType("工程");//业务类型
                                        gcgMsg.setBusinessName(dm);//业务名称
                                        gcgMsg.setTaskId(status.getTaskId());//任务id
                                        gcgMsg.setMsgType("收银账号已建完");//消息类型
                                        gcgMsg.setMessage(data);//消息内容
                                        gcgMsg.setPath(url1);//跳转路径
                                        gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                        gcgMsg.setReceiveUser(user1.getUserId());//接收人ID
                                        gcgMsg.setCreateTime(new Date());//创建时间

                                        //消息表新增收银系统消息
                                        msgMapper.insert(gcgMsg);
                                    }

                                    List list = new ArrayList();
                                    list.add(dd);

                                    //接收消息人id
                                    List<User> userList = btyWxMapper.getUser(list);

                                    if (ToolUtil.isNotEmpty(userList)) {
                                        for (User user : userList) {

                                            //收银系统url（督导）
                                            String syUrl = BusConst.SYDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                            String[] openids = new String[]{user.getOpenid()};

                                            //推送消息
                                            weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                            logger.info("======已推送督导收银账号已建完消息======");


                                            //消息表中新增收银系统消息
                                            GcgMsg gcgMsg1 = new GcgMsg();
                                            gcgMsg1.setBusinessId(status.getProId());//业务id
                                            gcgMsg1.setBusinessType("工程");//业务类型
                                            gcgMsg1.setBusinessName(dm);//业务名称
                                            gcgMsg1.setTaskId(status.getTaskId());//任务id
                                            gcgMsg1.setMsgType("收银账号已建完");//消息类型
                                            gcgMsg1.setMessage(data);//消息内容
                                            gcgMsg1.setPath(url);//跳转路径
                                            gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                            gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                            gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                            gcgMsg1.setCreateTime(new Date());//创建时间

                                            //消息表新增收银系统消息
                                            msgMapper.insert(gcgMsg1);
                                        }
                                    }



                                }

                            } else if (status.getContent() != null) {

                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                if (status.getStatus() != null) {
                                    taskFlow.setStatus(status.getStatus());//1提交；0审核未通过
                                } else {
                                    taskFlow.setStatus(1);
                                }
                                taskFlow.setTaskName(status.getTaskName());
                                taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                                taskFlow.setCreateTime(new Date());
                            }
                        //修改status表数据
                        taskMapper.updateCon(status);
                        //新增flow表数据
                        taskFlowMapper.add(taskFlow);
                    }

                    //新增任务内容填写
                } else {
                    if (status.getTaskName() != null) {
                        //查询该任务名称是否存在
                        int name = taskMapper.selectName(status.getTaskName());
                        //该工程中是否存在此名称
                        int taskName = taskMapper.selectTaskName(status.getTaskName(), status.getProId());
                        //该工程中没有填写此任务
                        if (taskName == 0) {
                            //名称不存在
                            if (name == 0) {
                                status.setStatus(1);//提交信息

                                taskStatuses.add(status);

                                //流程明细表
                                TaskFlow taskFlow = new TaskFlow();
                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                taskFlow.setStatus(1);//1提交；2审核未通过；3审核通过
                                if (status.getTaskName() != null || status.getTaskName() != "") {
                                    taskFlow.setTaskName(status.getTaskName());
                                }
                                taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                                taskFlow.setCreateTime(new Date());

                                taskFlows.add(taskFlow);

                            }
                        }
                    }
                }
            }

            if (taskStatuses.size() != 0) {
                //新增信息
                count = taskMapper.addRentList(taskStatuses);
                result.append(count > 0 ? 1 : 0);
            }

            if (taskFlows.size() != 0) {
                //新增流程明细表
                count = taskFlowMapper.addList(taskFlows);
                result.append(count > 0 ? 1 : 0);
            }

        }
        if (result.indexOf("0") >= 0) {
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseData.error("添加失败");
        } else {
            return ResponseData.success();
        }

    }

    /**
     * 新增任务信息
     *
     * @param taskStatus
     * @return
     * @throws ParseException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData addRentH5(List<TaskStatus> taskStatus,Long userId) throws ParseException {

        //修改状态,所有修改操作数据库新增条数必须都大于0才会提交事务
        StringBuilder result = new StringBuilder();
        // 数据库修改条数
        int count = 0;

        if (ToolUtil.isNotEmpty(taskStatus)) {

            //任务状态
            List<TaskStatus> taskStatuses = new ArrayList<>();
            //任务流水
            List<TaskFlow> taskFlows = new ArrayList<>();

            for (TaskStatus status : taskStatus) {

                //填写内容为固定项
                if (status.getTaskId() != null) {

                    //查询该工程该项是否已经填写信息
                    int msg = taskMapper.getRent(status.getProId(), status.getTaskId());

                    //之前没有填写过信息
                    if (msg == 0) {

                        //查询店名
                        String dm = taskMapper.selectDm(status.getProId());

                        if (status.getStatus() == null) {
                            status.setStatus(1);//提交信息
                        }
                        status.setCreateId(userId);

                        //不是可乐机, 不是出图日期新增,不是到货日期
                        if (status.getTaskId() != 19 && status.getTaskId() != 15) {
//                            && status.getTaskId() != 31
                            taskStatuses.add(status);
                            //是可乐机修改状态
                        } else if (status.getTaskId() == 19) {
                            taskMapper.updateStatus(status);

                            //通知督导
                            String now = DateUtil.getNow();//当前时间
                            String data = dm + "可乐机已确认";
                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机已确认", "可乐机已确认", now, data);

                            //推送督导可乐机已确认消息
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());
                            //督导
                            String dd = openidMap.get("dd");
                            //督导id
                            User user = btyWxMapper.selectUser(dd);
                            String[] openid = new String[]{user.getOpenid()};

                            //可乐机url（督导）
                            String kljUrl = BusConst.KLJDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kljUrl) + type + scope + state;

                            //推送督导消息
                            weChatSendTempMsgService.sendmsg(openid, url, tempObj);
                            logger.info("======已推送督导可乐机已确认消息======");

                            //消息表中新增可乐机消息
                            GcgMsg gcgMsg = new GcgMsg();
                            gcgMsg.setBusinessId(status.getProId());//业务id
                            gcgMsg.setBusinessType("工程");//业务类型
                            gcgMsg.setBusinessName(dm);//业务名称
                            gcgMsg.setTaskId(status.getTaskId());//任务id
                            gcgMsg.setMsgType("可乐机已确认");//消息类型
                            gcgMsg.setMessage(data);//消息内容
                            gcgMsg.setPath(url);//跳转路径
                            gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                            gcgMsg.setSendUser(userId);//发送人id
                            gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                            gcgMsg.setCreateTime(new Date());//创建时间

                            //消息表新增可乐机已确认消息
                            msgMapper.insert(gcgMsg);

                        }
                        //流程明细表
                        TaskFlow taskFlow = new TaskFlow();
                        taskFlow.setProId(status.getProId());
                        taskFlow.setTaskId(status.getTaskId());

                        if (status.getTaskName() != null || status.getTaskName() != "") {
                            taskFlow.setTaskName(status.getTaskName());
                        }
                        taskFlow.setCreateUser(userId);
                        taskFlow.setCreateTime(new Date());

                        //不是到货日期
                        if (status.getTaskId() != 15){
                            if (status.getStatus() != null) {
                                taskFlow.setStatus(status.getStatus());
                            } else {
                                taskFlow.setStatus(1);
                            }
                            //到货日期
                        }else {
                            taskFlow.setStatus(0);
                        }

                        taskFlows.add(taskFlow);

                        //开工日期
                        if (status.getTaskId() == 32) {
                            //刘书伟
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data = dm + "已确定开工日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;

                            logger.info("开工日期已确认=========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(userId);//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            //推送营运经理,督导工程开工消息
                            String data1 = dm + "已确定开工日期为:" + status.getContent() + ",请及时推进工作";
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "开工日期已确定", "开工日期已确定", DateUtil.getNow(), data1);
                            //查询工程督导,营运经理openID
                            Map<String, String> map = projectService.selectDd(status.getProId());
                            String dd = map.get("dd");
                            String yyjl = map.get("yyjl");

                            if (dd != null && yyjl != null) {
                                List<String> list = new ArrayList<>();
                                list.add(dd);
                                list.remove(yyjl);
                                list.add(yyjl);

                                //督导营运经理id
                                List<User> userList = btyWxMapper.getUser(list);
                                if (ToolUtil.isNotEmpty(userList)) {
                                    for (User user1 : userList) {
                                        //本店任务页面url
                                        String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                        String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;
                                        String[] openid = new String[]{user1.getOpenid()};

                                        //推送消息（本店任务页面）
                                        weChatSendTempMsgService.sendmsg(openid, url1, tempObj1);
                                        logger.info("=======推送督导,营运经理消息==========");

                                        //消息表中新增工程开工消息
                                        GcgMsg gcgMsg2 = new GcgMsg();
                                        gcgMsg2.setBusinessId(status.getProId());//业务id
                                        gcgMsg2.setBusinessType("工程");//业务类型
                                        gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                        gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                        gcgMsg2.setMessage(data1);//消息内容
                                        gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg2.setSendUser(userId);//发送人id
                                        gcgMsg2.setPath(url1);//跳转路径
                                        gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                        gcgMsg2.setCreateTime(new Date());//创建时间

                                        //消息表新增工程开工消息
                                        msgMapper.insert(gcgMsg2);

                                    }
                                }

                            } else if (yyjl != null) {
                                //营运经理id
                                User user1 = btyWxMapper.selectUser(yyjl);
                                //本店任务页面url
                                String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;

                                String[] yyjlOpenid = new String[]{yyjl};
                                //推送消息（本店任务页面）
                                weChatSendTempMsgService.sendmsg(yyjlOpenid, url1, tempObj1);
                                logger.info("=======推送营运经理消息==========");

                                //消息表中新增工程开工消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(userId);//发送人id
                                gcgMsg2.setPath(url1);//跳转路径
                                gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增工程开工消息
                                msgMapper.insert(gcgMsg2);

                            } else if (dd != null) {
                                //督导id
                                User user1 = btyWxMapper.selectUser(dd);
                                //本店任务页面url
                                String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;

                                String[] ddOpenid = new String[]{dd};
                                //推送消息（本店任务页面）
                                weChatSendTempMsgService.sendmsg(ddOpenid, url1, tempObj1);
                                logger.info("=======推送督导消息==========");

                                //消息表中新增工程开工消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(userId);//发送人id
                                gcgMsg2.setPath(url1);//跳转路径
                                gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增工程开工消息
                                msgMapper.insert(gcgMsg2);

                            } else {
                                logger.info("=======该工程暂无督导和营运经理==========");
                            }

                            //将门店同步到brand表
                            addBrand(status.getProId());

                            //预估完工日期
                        } else if (status.getTaskId() == 33) {

                            TaskStatus status1 = new TaskStatus();
                            //预估开业时间
                            status1.setTaskId(22);
                            //预估完工日期+7天
                            status1.setContent(DateUtil.addDate(status.getContent(), 7));
                            status1.setProId(status.getProId());
                            status1.setStatus(1);
                            status1.setTaskName("预估开业时间");
                            status1.setCreateId(userId);

                            taskStatuses.add(status1);

                            //流程明细表
                            TaskFlow taskFlow1 = new TaskFlow();
                            taskFlow1.setProId(status.getProId());
                            taskFlow1.setTaskId(22);
                            taskFlow1.setStatus(1);//1提交；0审核未通过
                            taskFlow1.setTaskName("预估开业时间");
                            taskFlow1.setCreateUser(userId);
                            taskFlow1.setCreateTime(new Date());

                            taskFlows.add(taskFlow1);
                        }

                        //确定工程开业日期
                        else if (status.getTaskId() == 16) {

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            Date toDate = sdf.parse(status.getContent());//开业日期

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setOpenDate(toDate);//开业日期
                            projectParam.setId(status.getProId());

                            //修改工程开业时间
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已添加开业时间========");

                            //收银系统负责人 (刘书伟)
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data = dm + "已确定开业日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;
                            logger.info("==========开业时间已确认========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(userId);//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            String data1 = dm + "已确定开业日期:" + status.getContent() + "。该店督导为：" + ddName + "电话为:" + ddTel;
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认开业日期", "开业日期", DateUtil.getNow(), data1);

                            //设计总监(朱小平)
                            String sjzj = BusConst.SJZJ;
                            String[] openids1 = new String[]{sjzj};


                            //设计总监(朱小平)id
                            User user1 = btyWxMapper.selectUser(sjzj);

                            if (ToolUtil.isNotEmpty(user1)){
                                //确定开业日期url（已确认）
                                String kyUrl = BusConst.KYURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kyUrl) + type + scope + state;

                                //推送设计总监消息
                                weChatSendTempMsgService.sendmsg(openids1, url1, tempObj1);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(status.getTaskId());//任务id
                                gcgMsg1.setMsgType("已确认开业日期提醒");//消息类型
                                gcgMsg1.setMessage(data1);//消息内容
                                gcgMsg1.setPath(url1);//跳转路径
                                gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(userId);//当前登录者id
                                gcgMsg1.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg1);
                            }

                            //丁玲
                            String dl = BusConst.DL;
                            String[] openid = new String[]{dl};
                            //丁玲id
                            User userDl = btyWxMapper.selectUser(dl);

                            if (ToolUtil.isNotEmpty(userDl)){
                                //推送丁玲消息
                                weChatSendTempMsgService.sendmsg(openid, BusConst.MSURL, tempObj1);
                                logger.info("=======推送丁玲消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
                                gcgMsg2.setTaskId(status.getTaskId());//任务id
                                gcgMsg2.setMsgType("已确认开业日期提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setPath(BusConst.MSURL);//跳转路径
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(userId);//当前登录者id
                                gcgMsg2.setReceiveUser(userDl.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg2);
                            }

                            //确认收银系统
                        } else if (status.getTaskId() == 21) {

                            if (status.getContent().equals("收银账号已建完，收银档案未建完")) {

                                //查询该工程的城市,营运经理,开业时间
                                Project project = projectMapper.selectProject(status.getProId());

                                if (ToolUtil.isNotEmpty(project)) {

                                    String btyDm = project.getName();
                                    //店名（截取省之后的字符）
                                    if (btyDm.contains("省") || btyDm.contains("自治区")){
                                        if (!project.getProvinceName().equals("北京") && !project.getProvinceName().equals("天津")
                                                && !project.getProvinceName().equals("上海") && !project.getProvinceName().equals("重庆")) {

                                            btyDm = project.getName().split(project.getProvinceName())[1].replaceAll("\\s*", "");
                                        }
                                    }

                                    //通讯录新增数据
                                    BtyTxl btyTxl = new BtyTxl();
                                    btyTxl.setCsqy(project.getProvinceName());//城市区域
                                    btyTxl.setYyjlqy(project.getYyjlName());//营运经理
                                    btyTxl.setDm(btyDm);//店名
                                    btyTxl.setKysj(project.getOpenTime());//开业时间
                                    btyTxl.setCtdz(project.getRestAddress());//餐厅地址
                                    btyTxl.setYytel(project.getYyjlTel());//营运经理电话
                                    btyTxlService.addct(btyTxl);


                                    //查询表中是否存在该数据
                                    int ddCount = btyTxlMapper.selectCount(btyDm, "督导");

                                    //bty_txl_ry表新增数据
                                    BtyTxlRY btyTxlRY = new BtyTxlRY();
                                    btyTxlRY.setZw("督导");//职务(督导)
                                    btyTxlRY.setFzr(project.getDdName());//负责人
                                    btyTxlRY.setLxfs(project.getDdTel());//联系方式
                                    btyTxlRY.setSsctdm(btyDm);//店名

                                    //不存在该数据
                                    if (ddCount == 0) {
                                        btyTxlMapper.addfzr(btyTxlRY);
                                    } else {
                                        btyTxlMapper.updateTxlRY(btyTxlRY);
                                    }

                                    //查询表中是否存在该数据
                                    int dzCount = btyTxlMapper.selectCount(btyDm, "店长");

                                    //bty_txl_ry表新增数据
                                    BtyTxlRY btyTxlRY1 = new BtyTxlRY();
                                    btyTxlRY1.setZw("店长");//职务(店长)
                                    btyTxlRY1.setFzr(project.getDz());//负责人
                                    btyTxlRY1.setLxfs(project.getDzTel());//联系方式
                                    btyTxlRY1.setSsctdm(btyDm);//店名

                                    //不存在该数据
                                    if (dzCount == 0) {
                                        btyTxlMapper.addfzr(btyTxlRY1);
                                    } else {
                                        btyTxlMapper.updateTxlRY(btyTxlRY1);
                                    }

                                    //btyy_region表新增数据
                                    BtyRegion btyRegion = new BtyRegion();
                                    btyRegion.setYyjl(project.getYyjlName());//营运经理
                                    btyRegion.setDm(btyDm);//店名
                                    btyRegion.setDd(project.getDdName());//督导
                                    btyRegion.setDz(project.getDz());//店长
                                    btyRegion.setCreateTime(new Date());
                                    this.regionMapper.insert(btyRegion);
                                }


                                //通知督导,韩铭渲
                                String now = DateUtil.getNow();//当前时间
                                String data = dm + "收银账号已建完";

                                JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);

                                Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                //督导
                                String dd = openidMap.get("dd");

                                List list = new ArrayList();
                                list.add(dd);

                                //接收消息人id
                                List<User> userList = btyWxMapper.getUser(list);
                                if (ToolUtil.isNotEmpty(userList)) {
                                    for (User user : userList) {

                                        //收银系统url(督导)
                                        String syUrl = BusConst.SYDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                                        String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                        String[] openids = new String[]{user.getOpenid()};

                                        //推送消息
                                        weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                        logger.info("======已推送督导收银账号已建完消息======");


                                        //消息表中新增收银系统消息
                                        GcgMsg gcgMsg1 = new GcgMsg();
                                        gcgMsg1.setBusinessId(status.getProId());//业务id
                                        gcgMsg1.setBusinessType("工程");//业务类型
                                        gcgMsg1.setBusinessName(dm);//业务名称
                                        gcgMsg1.setTaskId(status.getTaskId());//任务id
                                        gcgMsg1.setMsgType("收银账号已建完");//消息类型
                                        gcgMsg1.setMessage(data);//消息内容
                                        gcgMsg1.setPath(url);//跳转路径
                                        gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg1.setSendUser(userId);//发送人id(当前登录者id)
                                        gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                        gcgMsg1.setCreateTime(new Date());//创建时间

                                        //消息表新增收银系统消息
                                        msgMapper.insert(gcgMsg1);
                                    }
                                }

                                //收银档案负责人（韩铭渲）
                                String sy = BusConst.HMX;
                                String[] openid = new String[]{sy};
                                User user1 = btyWxMapper.selectUser(sy);

                                if (ToolUtil.isNotEmpty(user1)){
                                    //收银档案负责人url
                                    String syUrl = BusConst.DAURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                    String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                    //推送收银档案负责人消息
                                    weChatSendTempMsgService.sendmsg(openid, url1, tempObj);
                                    logger.info("======已推送收银档案负责人收银账号已建完消息======");

                                    //消息表中新增收银系统消息
                                    GcgMsg gcgMsg2 = new GcgMsg();
                                    gcgMsg2.setBusinessId(status.getProId());//业务id
                                    gcgMsg2.setBusinessType("工程");//业务类型
                                    gcgMsg2.setBusinessName(dm);//业务名称
                                    gcgMsg2.setTaskId(status.getTaskId());//任务id
                                    gcgMsg2.setMsgType("收银账号已建完");//消息类型
                                    gcgMsg2.setMessage(data);//消息内容
                                    gcgMsg2.setPath(url1);//跳转路径
                                    gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                    gcgMsg2.setSendUser(userId);//发送人id(当前登录者id)
                                    gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                    gcgMsg2.setCreateTime(new Date());//创建时间

                                    //消息表新增收银系统消息
                                    msgMapper.insert(gcgMsg2);
                                }
                            }

                        }
                        //卫生许可证
                        else if (status.getTaskId() == 44) {

                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());

                            //通讯录同步食品经营许可证数据
                            BtyTxl btyTxl = new BtyTxl();
                            btyTxl.setSpjyxk(status.getContent());//食品经营许可证
                            btyTxl.setCtbh(yaoma);//妖码
                            btyTxlService.edit(btyTxl);
                        }
                        //上传营业执照
                        else if (status.getTaskId() == 11) {

                            TaskStatus status1 = new TaskStatus();
                            //可乐机报备
                            status1.setTaskId(19);
                            status1.setProId(status.getProId());
                            status1.setStatus(0);
                            status1.setTaskName("可乐机");
                            status1.setContent("可乐机已报备");
                            status1.setCreateId(userId);

                            taskStatuses.add(status1);

                            //流程明细表
                            TaskFlow taskFlow1 = new TaskFlow();
                            taskFlow1.setProId(status.getProId());
                            taskFlow1.setTaskId(19);
                            taskFlow1.setStatus(0);//1提交；2审核未通过；3审核通过
                            taskFlow1.setTaskName("可乐机");
                            taskFlow1.setCreateUser(userId);
                            taskFlow1.setCreateTime(new Date());

                            taskFlows.add(taskFlow1);

                            //通知可乐机负责人
                            String now = DateUtil.getNow();//当前时间
                            String data = dm + "应入可乐机";

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机状态", "可乐机", now, data);

                            Long role = 1314488482857709570L;//可乐机负责人
                            List<String> openidlist = userService.listOpenidsByRole(role);

                            if (ToolUtil.isNotEmpty(openidlist)){
                                logger.info("=========可乐机负责人:" + openidlist + "========");
                                //可乐机负责人id
                                List<User> user1 = btyWxMapper.getUser(openidlist);

                                if (ToolUtil.isNotEmpty(user1)) {
                                    for (User user : user1) {

                                        //可乐机url
                                        String kljUrl = BusConst.KLJURL + "&proId=" + status.getProId() + "&taskId=19" + "&userId=" + user.getUserId();
                                        String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kljUrl) + type + scope + state;

                                        String[] openids = new String[]{user.getOpenid()};

                                        //推送消息
                                        weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                        logger.info("======已推送可乐机负责人消息======");


                                        //消息表中新增应入可乐机消息
                                        GcgMsg gcgMsg = new GcgMsg();
                                        gcgMsg.setBusinessId(status.getProId());//业务id
                                        gcgMsg.setBusinessType("工程");//业务类型
                                        gcgMsg.setBusinessName(dm);//业务名称
                                        gcgMsg.setTaskId(19);//任务id
                                        gcgMsg.setMsgType("应入可乐机提醒");//消息类型
                                        gcgMsg.setMessage(data);//消息内容
                                        gcgMsg.setPath(url);//跳转路径
                                        gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                        gcgMsg.setSendUser(userId);//发送人id
                                        gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                        gcgMsg.setCreateTime(new Date());//创建时间

                                        //消息表新增可乐机消息
                                        msgMapper.insert(gcgMsg);
                                    }
                                }
                            }

                            //刘书伟
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};
                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data1 = dm + "已填写营业执照信息，请确认收银系统。该店督导为：" + ddName + "电话为: " + ddTel;
                            logger.info("==========已填写营业执照信息========");

                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data1);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url(负责人)
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj1);
                                logger.info("===========推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(21);//任务id
                                gcgMsg1.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg1.setMessage(data);//消息内容
                                gcgMsg1.setPath(url);//跳转路径
                                gcgMsg1.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(userId);//发送人id
                                gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg1);
                            }

                            //配送要货完成
                        } else if (status.getTaskId() == 15) {

                            status.setStatus(0);//待发货
                            taskStatuses.add(status);

                            // 工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setArrivalTime(status.getContent());//到货日期
                            projectParam.setId(status.getProId());
                            projectParam.setPsStatus("0");//待发货

                            //修改工程到货日期
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已添加到货日期========");


                            //推送供应链消息
                            String data = dm + "已确认到货日期为" + status.getContent() + "，请尽快完成配送！";
                            logger.info("==========已完成配送========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "配送要货", "配送要货", DateUtil.getNow(), data);

//                            Long role = 1314441729702100993L;//供应链
                            Long role = 1278615893124055041L;//配送管理
                            List<String> list = userService.listOpenidsByRole(role);

                            if (ToolUtil.isNotEmpty(list)){
                                logger.info("=========配送管理:" + list + "========");
                                String[] openids = list.toArray(new String[list.size()]);
                                //推送消息
                                weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
                                logger.info("======推送配送管理消息======");
                            }

                        }


                        //之前填写过该项,修改数据
                    } else {

                        //流程明细表
                        TaskFlow taskFlow = new TaskFlow();

                        //修改预估完工日期
                        if (status.getTaskId() == 33) {

                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(33);
                            taskFlow.setStatus(1);//1提交；0审核未通过
                            taskFlow.setTaskName("预估完工日期");
                            taskFlow.setCreateUser(userId);
                            taskFlow.setCreateTime(new Date());

                            //判断是否因为逾期修改预估完工日期
                            if (ToolUtil.isNotEmpty(status.getNote())) {

                                Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                //督导
                                String dd = openidMap.get("dd");
                                //营运经理
                                String yyjl = openidMap.get("yyjl");
                                Long role_yyzj = 1305422678196678657L;//营运总监
                                List<String> openidlist = userService.listOpenidsByRole(role_yyzj);
                                if (ToolUtil.isEmpty(openidlist)) {
                                    logger.error("未找到营运总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========营运总监:" + openidlist + "========");

                                Long role_gczj = 1305422420779659266L;//工程总监
                                List<String> gclist = userService.listOpenidsByRole(role_gczj);
                                if (ToolUtil.isEmpty(gclist)) {
                                    logger.error("未找到工程总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========工程总监:" + gclist + "========");

                                Long role_kfzj = 1305422111420379138L;//开发总监
                                List<String> kflist = userService.listOpenidsByRole(role_kfzj);
                                if (ToolUtil.isEmpty(kflist)) {
                                    logger.error("未找到开发总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========开发总监:" + kflist + "========");

                                openidlist.remove(dd);
                                openidlist.add(dd);
                                openidlist.remove(yyjl);
                                openidlist.add(yyjl);
                                openidlist.removeAll(gclist);
                                openidlist.addAll(gclist);
                                openidlist.removeAll(kflist);
                                openidlist.addAll(kflist);

                                String[] openids = openidlist.toArray(new String[openidlist.size()]);

                                //查询店名
                                String dm = taskMapper.selectDm(status.getProId());

                                //查询开工时间
                                String con = taskMapper.selectCon(status.getProId(), 32).getContent();
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                                String dateSdf = sdf.format(new Date());//当前日期
                                Date date1 = null;
                                Date d1 = null;
                                long diffDays = 0;
                                Date wg = null;
                                long wgDays = 0;

                                try {
                                    date1 = sdf.parse(dateSdf);//当前日期
                                    d1 = sdf.parse(con);//开工时间
                                    String s = DateUtil.addDate(con, 28);//开工时间+28天(应该完工日期)
                                    wg = sdf.parse(s);

                                    //毫秒ms
                                    long diff = date1.getTime() - d1.getTime();//已开工时间
                                    diffDays = diff / (24 * 60 * 60 * 1000);//计算两个日期相差的时间

                                    //毫秒ms
                                    long diff1 = date1.getTime() - wg.getTime();//逾期时间
                                    wgDays = diff1 / (24 * 60 * 60 * 1000);//计算两个日期相差的时间
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }

                            }

                        } else
                            //确认收银系统
                            if (status.getTaskId() == 21) {
                                if (status.getContent() == "收银账号已建完，收银档案未建完") {

                                    //通知督导,设计
                                    String now = DateUtil.getNow();//当前时间
                                    //查询店名
                                    String dm = taskMapper.selectDm(status.getProId());
                                    String data = dm + "收银账号已建完";

                                    JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);

                                    Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                    //督导
                                    String dd = openidMap.get("dd");
                                    //设计(任召栋)
                                    String sj = BusConst.SJ;
                                    //设计(任召栋)
                                    String[] openid = new String[]{sj};


                                    //设计(任召栋)
                                    User user1 = btyWxMapper.selectUser(sj);

                                    if (ToolUtil.isNotEmpty(user1)){
                                        //收银系统url（设计）
                                        String sjUrl = BusConst.SYSJURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                        String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(sjUrl) + type + scope + state;
                                        //推送设计消息
                                        weChatSendTempMsgService.sendmsg(openid, url1, tempObj);
                                        logger.info("======已推送督导收银账号已建完消息======");

                                        //消息表中新增收银系统消息
                                        GcgMsg gcgMsg = new GcgMsg();
                                        gcgMsg.setBusinessId(status.getProId());//业务id
                                        gcgMsg.setBusinessType("工程");//业务类型
                                        gcgMsg.setBusinessName(dm);//业务名称
                                        gcgMsg.setTaskId(status.getTaskId());//任务id
                                        gcgMsg.setMsgType("收银账号已建完");//消息类型
                                        gcgMsg.setMessage(data);//消息内容
                                        gcgMsg.setPath(url1);//跳转路径
                                        gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg.setSendUser(userId);//发送人id(当前登录者id)
                                        gcgMsg.setReceiveUser(user1.getUserId());//接收人ID
                                        gcgMsg.setCreateTime(new Date());//创建时间

                                        //消息表新增收银系统消息
                                        msgMapper.insert(gcgMsg);
                                    }

                                    List list = new ArrayList();
                                    list.add(dd);

                                    //接收消息人id
                                    List<User> userList = btyWxMapper.getUser(list);

                                    if (ToolUtil.isNotEmpty(userList)) {
                                        for (User user : userList) {

                                            //收银系统url（督导）
                                            String syUrl = BusConst.SYDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                            String[] openids = new String[]{user.getOpenid()};

                                            //推送消息
                                            weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                            logger.info("======已推送督导收银账号已建完消息======");


                                            //消息表中新增收银系统消息
                                            GcgMsg gcgMsg1 = new GcgMsg();
                                            gcgMsg1.setBusinessId(status.getProId());//业务id
                                            gcgMsg1.setBusinessType("工程");//业务类型
                                            gcgMsg1.setBusinessName(dm);//业务名称
                                            gcgMsg1.setTaskId(status.getTaskId());//任务id
                                            gcgMsg1.setMsgType("收银账号已建完");//消息类型
                                            gcgMsg1.setMessage(data);//消息内容
                                            gcgMsg1.setPath(url);//跳转路径
                                            gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                            gcgMsg1.setSendUser(userId);//发送人id(当前登录者id)
                                            gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                            gcgMsg1.setCreateTime(new Date());//创建时间

                                            //消息表新增收银系统消息
                                            msgMapper.insert(gcgMsg1);
                                        }
                                    }



                                }

                            } else if (status.getContent() != null) {

                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                if (status.getStatus() != null) {
                                    taskFlow.setStatus(status.getStatus());//1提交；0审核未通过
                                } else {
                                    taskFlow.setStatus(1);
                                }
                                taskFlow.setTaskName(status.getTaskName());
                                taskFlow.setCreateUser(userId);
                                taskFlow.setCreateTime(new Date());
                            }
                        //修改status表数据
                        taskMapper.updateCon(status);
                        //新增flow表数据
                        taskFlowMapper.add(taskFlow);
                    }

                    //新增任务内容填写
                } else {
                    if (status.getTaskName() != null) {
                        //查询该任务名称是否存在
                        int name = taskMapper.selectName(status.getTaskName());
                        //该工程中是否存在此名称
                        int taskName = taskMapper.selectTaskName(status.getTaskName(), status.getProId());
                        //该工程中没有填写此任务
                        if (taskName == 0) {
                            //名称不存在
                            if (name == 0) {
                                status.setStatus(1);//提交信息

                                taskStatuses.add(status);

                                //流程明细表
                                TaskFlow taskFlow = new TaskFlow();
                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                taskFlow.setStatus(1);//1提交；2审核未通过；3审核通过
                                if (status.getTaskName() != null || status.getTaskName() != "") {
                                    taskFlow.setTaskName(status.getTaskName());
                                }
                                taskFlow.setCreateUser(userId);
                                taskFlow.setCreateTime(new Date());

                                taskFlows.add(taskFlow);

                            }
                        }
                    }
                }
            }

            if (taskStatuses.size() != 0) {
                //新增信息
                count = taskMapper.addRentList(taskStatuses);
                result.append(count > 0 ? 1 : 0);
            }

            if (taskFlows.size() != 0) {
                //新增流程明细表
                count = taskFlowMapper.addList(taskFlows);
                result.append(count > 0 ? 1 : 0);
            }

        }
        if (result.indexOf("0") >= 0) {
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseData.error("添加失败");
        } else {
            return ResponseData.success();
        }

    }


    /**
     * 确认到货修改
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData editDh(Integer proId) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String toDate = sdf.format(new Date());

        //修改project表到货状态
        ProjectParam project = new ProjectParam();
        project.setId(proId);
        project.setPsStatus("2");//已到货
        project.setDhTime(toDate);
        //修改工程到货日期
        projectMapper.updateProjectByCondition(project);
        return ResponseData.success();
    }

    /**
     * 新增任务信息
     *
     * @param taskStatus
     * @return
     * @throws ParseException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData addRentAdmin(List<TaskStatus> taskStatus) throws ParseException {
        if (ToolUtil.isEmpty(taskStatus)) {
            return ResponseData.error("数据不能为空");
        }
        boolean isexist = taskStatusService.isexist(taskStatus.get(0).getProId(), ProjectTaskEnum.TASK_41.getCode().toString());
        if(!isexist){
            return ResponseData.error(BusExceptionEnum.ERR_NO_DDOK.getMessage());
        }

//        if (ToolUtil.isNotEmpty(taskStatus)) {

            //任务状态
            List<TaskStatus> taskStatuses = new ArrayList<>();
            //任务流水
            List<TaskFlow> taskFlows = new ArrayList<>();
            List<WxPushParamObj> pushList = new ArrayList<>();

            Map<String, String> openidMap = projectService.selectDd(taskStatus.get(0).getProId());

            for (TaskStatus status : taskStatus) {
                //填写内容为固定项
                if (status.getTaskId() != null) {
                    //查询该工程该项是否已经填写信息
                    int msg = taskMapper.getRent(status.getProId(), status.getTaskId());
                    if(msg!=0){
                        //营业执照名称
                        if(status.getTaskId() == 56 && ToolUtil.isNotEmpty(status.getContent())){
                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());
                            if(ToolUtil.isNotEmpty(yaoma)){
                                BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                if(ToolUtil.isNotEmpty(txl)){
                                    txl.setYyzzmc(status.getContent());
                                    btyTxlService.updateById(txl);
                                }
                            }

                        }
                        //统一社会信用代码
                        else if(status.getTaskId() == 57 && ToolUtil.isNotEmpty(status.getContent())){
                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());
                            if(ToolUtil.isNotEmpty(yaoma)){
                                BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                if(ToolUtil.isNotEmpty(txl)){
                                    txl.setShxydm(status.getContent());
                                    btyTxlService.updateById(txl);
                                }
                            }
                        }
                    }
                    //之前没有填写过信息
                    if (msg == 0) {
                        //查询店名
                        String dm = taskMapper.selectDm(status.getProId());
                        if (status.getStatus() == null) {
                            status.setStatus(1);//提交信息
                        }
                        //不是可乐机新增，不是到货日期
                        if (status.getTaskId() != 19 && status.getTaskId() != 15) {
                            taskStatuses.add(status);
                            //是可乐机修改状态
                        } else if (status.getTaskId() == 19) {
                            taskMapper.updateStatus(status);
                            //通知督导
                            String now = DateUtil.getNow();//当前时间
                            String data = dm + "可乐机已确认";
                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机已确认。", "可乐机已确认。", now, data);

                            //推送督导可乐机已确认消息
//                            Map<String, String> openidMap = projectService.selectDd(status.getProId());
                            //督导
                            String dd = openidMap.get("dd");
                            //督导id
                            User user = btyWxMapper.selectUser(dd);
                            if(ToolUtil.isEmpty(user)){
//                               throw new BusException(BusExceptionEnum.ERR_NO_USER);
                                logger.error("未找到督导-{}的用户信息",dd);
                            }
                            String[] openid = new String[]{user.getOpenid()};

                            //可乐机url（督导）
                            String kljUrl = BusConst.KLJDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kljUrl) + type + scope + state;
                            //推送督导消息
//                            weChatSendTempMsgService.sendmsg(openid, url, tempObj);
//                            logger.info("======已推送督导可乐机已确认消息======");
                              pushList.add(new WxPushParamObj(openid,url,tempObj));

                            //消息表中新增可乐机消息
                            GcgMsg gcgMsg = new GcgMsg();
                            gcgMsg.setBusinessId(status.getProId());//业务id
                            gcgMsg.setBusinessType("工程");//业务类型
                            gcgMsg.setBusinessName(dm);//业务名称
                            gcgMsg.setTaskId(status.getTaskId());//任务id
                            gcgMsg.setMsgType("可乐机已确认");//消息类型
                            gcgMsg.setMessage(data);//消息内容
                            gcgMsg.setPath(url);//跳转路径
                            gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                            gcgMsg.setSendUser(status.getCreateId());//发送人id
                            gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                            gcgMsg.setCreateTime(new Date());//创建时间

                            //消息表新增可乐机已确认消息
                            msgMapper.insert(gcgMsg);

                        }

//                        taskStatuses.add(status);

                        //流程明细表
                        TaskFlow taskFlow = new TaskFlow();
                        taskFlow.setProId(status.getProId());
                        taskFlow.setTaskId(status.getTaskId());

                        //不是到货日期
                        if (status.getTaskId() != 15){
                            if (status.getStatus() != null) {
                                taskFlow.setStatus(status.getStatus());
                            } else {
                                taskFlow.setStatus(1);
                            }
                            //到货日期
                        }else {
                            taskFlow.setStatus(0);
                        }


                        if (status.getTaskName() != null || status.getTaskName() != "") {
                            taskFlow.setTaskName(status.getTaskName());
                        }
                        taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                        taskFlow.setCreateTime(new Date());

                        taskFlows.add(taskFlow);

                        //开工日期
                        if (status.getTaskId() == ProjectTaskEnum.TASK_32.getCode()) {
                            //刘书伟
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
//                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data = dm + "已确定开工日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;
                            logger.info("开工日期已确认=========");
                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统.", "收银系统.", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
//                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                pushList.add(new WxPushParamObj(openids,url,tempObj));
//                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间
                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            //推送营运经理,督导工程开工消息
                            String data1 = dm + "已确定开工日期为:" + status.getContent() + ",请及时推进工作";
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "开工日期已确定.", "开工日期已确定.", DateUtil.getNow(), data1);
                            //查询工程督导,营运经理openID
//                            Map<String, String> map = projectService.selectDd(status.getProId());
                            String dd = openidMap.get("dd");
                            String yyjl = openidMap.get("yyjl");

                            if (dd != null && yyjl != null) {
                                List<String> list = new ArrayList<>();
                                list.add(dd);
                                list.add(yyjl);

                                //督导营运经理id
                                List<User> userList = btyWxMapper.getUser(list);
                                if (ToolUtil.isNotEmpty(userList)) {
                                    for (User user1 : userList) {
                                        //本店任务页面url
                                        String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                        String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;
                                        String[] openid = new String[]{user1.getOpenid()};

                                        //推送消息（本店任务页面）
//                                        weChatSendTempMsgService.sendmsg(openid, url1, tempObj1);
                                        pushList.add(new WxPushParamObj(openid,url1,tempObj1));
//                                        logger.info("=======推送督导,营运经理消息==========");

                                        //消息表中新增工程开工消息
                                        GcgMsg gcgMsg2 = new GcgMsg();
                                        gcgMsg2.setBusinessId(status.getProId());//业务id
                                        gcgMsg2.setBusinessType("工程");//业务类型
                                        gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                        gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                        gcgMsg2.setMessage(data1);//消息内容
                                        gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                        gcgMsg2.setPath(url1);//跳转路径
                                        gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                        gcgMsg2.setCreateTime(new Date());//创建时间
                                        //消息表新增工程开工消息
                                        msgMapper.insert(gcgMsg2);
                                    }
                                }

                            } else if (yyjl != null) {
                                //营运经理id
                                User user1 = btyWxMapper.selectUser(yyjl);

                                if (ToolUtil.isNotEmpty(user1)){
                                    //本店任务页面url
                                    String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                    String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;
                                    String[] yyjlOpenid = new String[]{yyjl};
                                    //推送消息（本店任务页面）
//                                weChatSendTempMsgService.sendmsg(yyjlOpenid, url1, tempObj1);
//                                logger.info("=======推送营运经理消息==========");
                                    pushList.add(new WxPushParamObj(yyjlOpenid, url1, tempObj1));

                                    //消息表中新增工程开工消息
                                    GcgMsg gcgMsg2 = new GcgMsg();
                                    gcgMsg2.setBusinessId(status.getProId());//业务id
                                    gcgMsg2.setBusinessType("工程");//业务类型
                                    gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                    gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                    gcgMsg2.setMessage(data1);//消息内容
                                    gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                    gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                    gcgMsg2.setPath(url1);//跳转路径
                                    gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                    gcgMsg2.setCreateTime(new Date());//创建时间

                                    //消息表新增工程开工消息
                                    msgMapper.insert(gcgMsg2);
                                }

                            } else if (dd != null) {
                                //督导id
                                User user1 = btyWxMapper.selectUser(dd);

                                if(ToolUtil.isNotEmpty(user1)){
                                    //本店任务页面url
                                    String bdUrl = BusConst.BDURL + "&proId=" + status.getProId() + "&userId=" + user1.getUserId();
                                    String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(bdUrl) + type + scope + state;
                                    String[] ddOpenid = new String[]{dd};
                                    //推送消息（本店任务页面）
//                                weChatSendTempMsgService.sendmsg(ddOpenid, url1, tempObj1);
                                    pushList.add(new WxPushParamObj(ddOpenid, url1, tempObj1));
//                                logger.info("=======推送督导消息==========");

                                    //消息表中新增工程开工消息
                                    GcgMsg gcgMsg2 = new GcgMsg();
                                    gcgMsg2.setBusinessId(status.getProId());//业务id
                                    gcgMsg2.setBusinessType("工程");//业务类型
                                    gcgMsg2.setBusinessName(dm);//业务名称
//                                        gcgMsg2.setTaskId(19);//任务id
                                    gcgMsg2.setMsgType("工程开工提醒");//消息类型
                                    gcgMsg2.setMessage(data1);//消息内容
                                    gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                    gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                    gcgMsg2.setPath(url1);//跳转路径
                                    gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                    gcgMsg2.setCreateTime(new Date());//创建时间

                                    //消息表新增工程开工消息
                                    msgMapper.insert(gcgMsg2);

                                }

                            } else {
                                logger.info("=======该工程暂无督导和营运经理==========");
                            }

                            //人事部
                            Long role = 1277443924781469698L;//人事部
                            List<String> openidlist = userService.listOpenidsByRole(role);
                            String[] rsOpenids = openidlist.toArray(new String[openidlist.size()]);
                            if (ToolUtil.isNotEmpty(rsOpenids)){
                                //推送人事部消息
                                String rsData = dm + "已确定开工日期为:" + status.getContent() + ",需要建档案。该店督导为：" + ddName + "电话为:" + ddTel;
                                logger.info("开工日期已确认=========");
                                JSONObject rsTempObj = weChatSendTempMsgService.setTempParam(dm, null, "建档案", "建档案", DateUtil.getNow(), rsData);
                                //推送消息
//                                weChatSendTempMsgService.sendmsg(rsOpenids, BusConst.MSURL, rsTempObj);

                                pushList.add(new WxPushParamObj(rsOpenids,BusConst.MSURL,rsTempObj));

                                logger.info("=======推送消息给人事部==========");
                            }

                            //将门店同步到brand表
                            addBrand(status.getProId());

                            //预估完工日期
                        } else if (status.getTaskId() == ProjectTaskEnum.TASK_33.getCode()) {

                            TaskStatus status1 = new TaskStatus();
                            //预估开业时间
                            status1.setTaskId(22);
                            //预估完工日期+7天
                            status1.setContent(DateUtil.addDate(status.getContent(), 7));
                            status1.setProId(status.getProId());
                            status1.setStatus(1);
                            status1.setTaskName("预估开业时间");

                            taskStatuses.add(status1);

                            //流程明细表
                            TaskFlow taskFlow1 = new TaskFlow();
                            taskFlow1.setProId(status.getProId());
                            taskFlow1.setTaskId(22);
                            taskFlow1.setStatus(1);//1提交；0审核未通过
                            taskFlow1.setTaskName("预估开业时间");
                            taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
                            taskFlow1.setCreateTime(new Date());

                            taskFlows.add(taskFlow1);

                        }

                        //确定工程开业日期
                        else if (status.getTaskId() == ProjectTaskEnum.TASK_16.getCode()) {

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            Date toDate = sdf.parse(status.getContent());//开业日期

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setOpenDate(toDate);//开业日期
                            projectParam.setId(status.getProId());

                            //修改工程开业时间
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已添加开业时间========");

                            //收银系统负责人 (刘书伟)
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
//                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data = dm + "已确定开业日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;
                            logger.info("==========开业时间已确认========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统.", "收银系统.", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
//                            weChatSendTempMsgService.sendmsg(openids, url, tempObj);
//                            logger.info("=======推送收银系统负责人消息==========");
                                pushList.add(new WxPushParamObj(openids, url, tempObj));

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            String data1 = dm + "已确定开业日期:" + status.getContent()+ "。该店督导为：" + ddName + "电话为:" + ddTel;
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认开业日期.", "开业日期.", DateUtil.getNow(), data1);

                            //设计总监(朱小平)
                            String sjzj = BusConst.SJZJ;
                            String[] openids1 = new String[]{sjzj};
//                            //推送设计总监消息
                            //weChatSendTempMsgService.sendmsg(openids1, BusConst.MSURL, tempObj1);
                            //logger.info("========推送设计总监消息==========");

                            //设计总监(朱小平)id
                            User user1 = btyWxMapper.selectUser(sjzj);

                            if (ToolUtil.isNotEmpty(user1)){
                                //确定开业日期url（已确认）
                                String kyUrl = BusConst.KYURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kyUrl) + type + scope + state;

                                //推送设计总监消息
//                            weChatSendTempMsgService.sendmsg(openids1, url1, tempObj1);
//                            logger.info("=======推送收银系统负责人消息==========");
                                pushList.add(new WxPushParamObj(openids1, url1, tempObj1));

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(status.getTaskId());//任务id
                                gcgMsg1.setMsgType("已确认开业日期提醒");//消息类型
                                gcgMsg1.setMessage(data1);//消息内容
                                gcgMsg1.setPath(url1);//跳转路径
                                gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg1.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg1);
                            }

                            //丁玲
                            String dl = BusConst.DL;
                            String[] openid = new String[]{dl};
                            //丁玲id
                            User userDl = btyWxMapper.selectUser(dl);
                            //推送丁玲消息
//                            weChatSendTempMsgService.sendmsg(openid, BusConst.MSURL, tempObj1);
//                            logger.info("=======推送丁玲消息==========");

                            if (ToolUtil.isNotEmpty(userDl)){
                                pushList.add(new WxPushParamObj(openid, BusConst.MSURL, tempObj1));

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
                                gcgMsg2.setTaskId(status.getTaskId());//任务id
                                gcgMsg2.setMsgType("已确认开业日期提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setPath(BusConst.MSURL);//跳转路径
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//当前登录者id
                                gcgMsg2.setReceiveUser(userDl.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg2);
                            }

                            //确认收银系统
                        } else if (status.getTaskId() == ProjectTaskEnum.TASK_21.getCode()) {

                            if (status.getContent().equals("收银账号已建完，收银档案未建完")) {

                                addTxl(status.getProId(), null, status.getTaskId());

//                                //查询该工程的城市,营运经理,开业时间
//                                Project project = projectMapper.selectProject(status.getProId());
//
//                                if (ToolUtil.isNotEmpty(project)) {
//
//                                    String btyDm = project.getName();
//                                    //店名（截取省之后的字符）
//                                    if (!project.getProvinceName().equals("北京") && !project.getProvinceName().equals("天津")
//                                            && !project.getProvinceName().equals("上海") && !project.getProvinceName().equals("重庆")) {
//
//                                        btyDm = project.getName().split(project.getProvinceName())[1].replaceAll("\\s*", "");
//                                    }
//
//
//                                    //通讯录新增数据
//                                    BtyTxl btyTxl = new BtyTxl();
//                                    btyTxl.setCsqy(project.getProvinceName());//城市区域
//                                    btyTxl.setYyjlqy(project.getYyjlName());//营运经理
//                                    btyTxl.setDm(btyDm);//店名
//                                    btyTxl.setKysj(project.getOpenTime());//开业时间
//                                    btyTxl.setCtdz(project.getRestAddress());//餐厅地址
//                                    btyTxl.setYytel(project.getYyjlTel());//营运经理电话
//                                    btyTxlService.addct(btyTxl);
//
//
//                                    //查询表中是否存在该数据
//                                    int ddCount = btyTxlMapper.selectCount(btyDm, "督导");
//
//                                    //bty_txl_ry表新增数据
//                                    BtyTxlRY btyTxlRY = new BtyTxlRY();
//                                    btyTxlRY.setZw("督导");//职务(督导)
//                                    btyTxlRY.setFzr(project.getDdName());//负责人
//                                    btyTxlRY.setLxfs(project.getDdTel());//联系方式
//                                    btyTxlRY.setSsctdm(btyDm);//店名
//
//                                    //不存在该数据
//                                    if (ddCount == 0) {
//                                        btyTxlMapper.addfzr(btyTxlRY);
//                                    } else {
//                                        btyTxlMapper.updateTxlRY(btyTxlRY);
//                                    }
//
//                                    //查询表中是否存在该数据
//                                    int dzCount = btyTxlMapper.selectCount(btyDm, "店长");
//
//                                    //bty_txl_ry表新增数据
//                                    BtyTxlRY btyTxlRY1 = new BtyTxlRY();
//                                    btyTxlRY1.setZw("店长");//职务(店长)
//                                    btyTxlRY1.setFzr(project.getDz());//负责人
//                                    btyTxlRY1.setLxfs(project.getDzTel());//联系方式
//                                    btyTxlRY1.setSsctdm(btyDm);//店名
//
//                                    //不存在该数据
//                                    if (dzCount == 0) {
//                                        btyTxlMapper.addfzr(btyTxlRY1);
//                                    } else {
//                                        btyTxlMapper.updateTxlRY(btyTxlRY1);
//                                    }
//
//                                    //btyy_region表新增数据
//                                    BtyRegion btyRegion = new BtyRegion();
//                                    btyRegion.setYyjl(project.getYyjlName());//营运经理
//                                    btyRegion.setDm(btyDm);//店名
//                                    btyRegion.setDd(project.getDdName());//督导
//                                    btyRegion.setDz(project.getDz());//店长
//                                    btyRegion.setCreateTime(new Date());
//                                    this.regionMapper.insert(btyRegion);
//                                }


                                //通知督导,韩铭渲
                                String now = DateUtil.getNow();//当前时间
                                String data = dm + "收银账号已建完";

                                JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);

//                                Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                //督导
                                String dd = openidMap.get("dd");

                                List list = new ArrayList();
                                list.add(dd);

                                //接收消息人id
                                List<User> userList = btyWxMapper.getUser(list);
                                if (ToolUtil.isNotEmpty(userList)) {
                                    for (User user : userList) {

                                        //收银系统url(督导)
                                        String syUrl = BusConst.SYDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                                        String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                        String[] openids = new String[]{user.getOpenid()};

                                        //推送消息
//                                        weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                        pushList.add(new WxPushParamObj(openids, url, tempObj));
                                        logger.info("======已推送督导收银账号已建完消息======");


                                        //消息表中新增收银系统消息
                                        GcgMsg gcgMsg1 = new GcgMsg();
                                        gcgMsg1.setBusinessId(status.getProId());//业务id
                                        gcgMsg1.setBusinessType("工程");//业务类型
                                        gcgMsg1.setBusinessName(dm);//业务名称
                                        gcgMsg1.setTaskId(status.getTaskId());//任务id
                                        gcgMsg1.setMsgType("收银账号已建完");//消息类型
                                        gcgMsg1.setMessage(data);//消息内容
                                        gcgMsg1.setPath(url);//跳转路径
                                        gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                        gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                        gcgMsg1.setCreateTime(new Date());//创建时间

                                        //消息表新增收银系统消息
                                        msgMapper.insert(gcgMsg1);
                                    }
                                }

                                //收银档案负责人（韩铭渲）
                                String sy = BusConst.HMX;
                                String[] openid = new String[]{sy};
                                User user1 = btyWxMapper.selectUser(sy);

                                if (ToolUtil.isNotEmpty(user1)){
                                    //收银档案负责人url
                                    String syUrl = BusConst.DAURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                    String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                    //推送收银档案负责人消息
//                                weChatSendTempMsgService.sendmsg(openid, url1, tempObj);
                                    pushList.add(new WxPushParamObj(openid, url1, tempObj));
                                    logger.info("======已推送收银档案负责人收银账号已建完消息======");

                                    //消息表中新增收银系统消息
                                    GcgMsg gcgMsg2 = new GcgMsg();
                                    gcgMsg2.setBusinessId(status.getProId());//业务id
                                    gcgMsg2.setBusinessType("工程");//业务类型
                                    gcgMsg2.setBusinessName(dm);//业务名称
                                    gcgMsg2.setTaskId(status.getTaskId());//任务id
                                    gcgMsg2.setMsgType("收银账号已建完");//消息类型
                                    gcgMsg2.setMessage(data);//消息内容
                                    gcgMsg2.setPath(url1);//跳转路径
                                    gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                    gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                    gcgMsg2.setReceiveUser(user1.getUserId());//接收人ID
                                    gcgMsg2.setCreateTime(new Date());//创建时间

                                    //消息表新增收银系统消息
                                    msgMapper.insert(gcgMsg2);
                                }
                            }

                        }
                        //卫生许可证
                        else if (status.getTaskId() == 44) {

                            addTxl(status.getProId(), status.getContent(), status.getTaskId());

//                            //获取妖码
//                            String yaoma = projectMapper.getYm(status.getProId());
//
//                            //通讯录同步食品经营许可证数据
//                            BtyTxl btyTxl = new BtyTxl();
//                            btyTxl.setSpjyxk(status.getContent());//食品经营许可证
//                            btyTxl.setCtbh(yaoma);//妖码
//                            btyTxlService.edit(btyTxl);
                        }
//
                        //上传营业执照
                        else if (status.getTaskId() == ProjectTaskEnum.TASK_11.getCode()) {

                            TaskStatus status1 = new TaskStatus();
                            //可乐机报备
                            status1.setTaskId(19);
                            status1.setProId(status.getProId());
                            status1.setStatus(0);
                            status1.setTaskName("可乐机");
                            status1.setContent("可乐机已报备");
                            status1.setCreateId(status.getCreateId());

                            taskStatuses.add(status1);

                            //流程明细表
                            TaskFlow taskFlow1 = new TaskFlow();
                            taskFlow1.setProId(status.getProId());
                            taskFlow1.setTaskId(19);
                            taskFlow1.setStatus(0);//1提交；2审核未通过；3审核通过
                            taskFlow1.setTaskName("可乐机");
                            taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
                            taskFlow1.setCreateTime(new Date());

                            taskFlows.add(taskFlow1);

                            //通知可乐机负责人
                            String now = DateUtil.getNow();//当前时间
                            String data = dm + "应入可乐机";

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "可乐机状态.", "可乐机", now, data);

                            Long role = RoleIdEnum.ROLE_KELEJI.getCode();//可乐机负责人
                            List<String> openidlist = userService.listOpenidsByRole(role);

                            if (ToolUtil.isNotEmpty(openidlist)){
                                logger.info("=========可乐机负责人:" + openidlist + "========");

                                //可乐机负责人id
                                List<User> user1 = btyWxMapper.getUser(openidlist);

                                if (ToolUtil.isNotEmpty(user1)) {
                                    for (User user : user1) {

                                        //可乐机url
                                        String kljUrl = BusConst.KLJURL + "&proId=" + status.getProId() + "&taskId=19" + "&userId=" + user.getUserId();
                                        String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kljUrl) + type + scope + state;
                                        String[] openids = new String[]{user.getOpenid()};
                                        //推送消息
//                                    weChatSendTempMsgService.sendmsg(openids, url, tempObj);
//                                    logger.info("======已推送可乐机负责人消息======");
                                        pushList.add(new WxPushParamObj(openids, url, tempObj));

                                        //消息表中新增应入可乐机消息
                                        GcgMsg gcgMsg = new GcgMsg();
                                        gcgMsg.setBusinessId(status.getProId());//业务id
                                        gcgMsg.setBusinessType("工程");//业务类型
                                        gcgMsg.setBusinessName(dm);//业务名称
                                        gcgMsg.setTaskId(19);//任务id
                                        gcgMsg.setMsgType("应入可乐机提醒");//消息类型
                                        gcgMsg.setMessage(data);//消息内容
                                        gcgMsg.setPath(url);//跳转路径
                                        gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                        gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
                                        gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                        gcgMsg.setCreateTime(new Date());//创建时间

                                        //消息表新增可乐机消息
                                        msgMapper.insert(gcgMsg);
                                    }
                                }
                            }

                            //刘书伟
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};
                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);

//                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");

                            //推送收银系统确认消息
                            String data1 = dm + "已填写营业执照信息，请确认收银系统。该店督导为：" + ddName + "电话为: " + ddTel;
                            logger.info("==========已填写营业执照信息========");

                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统.", DateUtil.getNow(), data1);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url(负责人)
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
//                            weChatSendTempMsgService.sendmsg(openids, url, tempObj1);
//                            logger.info("===========推送收银系统负责人消息==========");
                                pushList.add(new WxPushParamObj(openids, url, tempObj1));

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(21);//任务id
                                gcgMsg1.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg1.setMessage(data);//消息内容
                                gcgMsg1.setPath(url);//跳转路径
                                gcgMsg1.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(status.getCreateId());//发送人id
                                gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg1);
                            }

                            //配送要货完成
                        } else if (status.getTaskId() == ProjectTaskEnum.TASK_15.getCode()) {

                            status.setStatus(0);//待发货
                            taskStatuses.add(status);

//                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//                            Date toDate = sdf.parse(status.getContent());//到货日期

                            // 工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setArrivalTime(status.getContent());//到货日期
                            projectParam.setId(status.getProId());
                            projectParam.setPsStatus("0");//待发货

                            //修改工程到货日期
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已添加到货日期========");


                            //推送供应链消息
                            String data = dm + "已确认到货日期为" + status.getContent() + "，请尽快完成配送！";
                            logger.info("==========已完成配送========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "配送要货.", "配送要货", DateUtil.getNow(), data);

                            Long role = RoleIdEnum.ROLE_PS.getCode();//配送管理
                            List<String> list = userService.listOpenidsByRole(role);
                            if (ToolUtil.isEmpty(list)) {
                                logger.error("未找到配送管理微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                            }
                            logger.info("=========配送管理:" + list + "========");

                            String[] openids = list.toArray(new String[list.size()]);
                            //推送消息
                            weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
                            logger.info("======推送配送管理消息======");


//                            //配送管理id
//                            List<User> user1 = btyWxMapper.getUser(list);
//                            if (ToolUtil.isNotEmpty(user1)) {
//                                for (User user : user1) {
//                                    //配送要货url
//                                    String psyhUrl = BusConst.PSYHURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
//                                    String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(psyhUrl) + type + scope + state;
//                                    String[] openids = new String[]{user.getOpenid()};
//                                    //推送消息
////                                    weChatSendTempMsgService.sendmsg(openids, url, tempObj);
////                                    logger.info("======推送供应链消息======");
//                                    pushList.add(new WxPushParamObj(openids, url, tempObj));
//
//                                    //消息表中新增配送要货完成消息
//                                    GcgMsg gcgMsg = new GcgMsg();
//                                    gcgMsg.setBusinessId(status.getProId());//业务id
//                                    gcgMsg.setBusinessType("工程");//业务类型
//                                    gcgMsg.setBusinessName(dm);//业务名称
//                                    gcgMsg.setTaskId(status.getTaskId());//任务id
//                                    gcgMsg.setMsgType("推送配送管理消息");//消息类型
//                                    gcgMsg.setMessage(data);//消息内容
//                                    gcgMsg.setPath(url);//跳转路径
//                                    gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
//                                    gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id
//                                    gcgMsg.setReceiveUser(user.getUserId());//接收人ID
//                                    gcgMsg.setCreateTime(new Date());//创建时间
//
//                                    //消息表新增配送要货完成消息
//                                    msgMapper.insert(gcgMsg);
//                                }
//                            }

                        }


                        //之前填写过该项,修改数据
                    } else {

                        //流程明细表
                        TaskFlow taskFlow = new TaskFlow();

                        //修改预估完工日期
                        if (status.getTaskId() == 33) {

                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(33);
                            taskFlow.setStatus(1);//1提交；0审核未通过
                            taskFlow.setTaskName("预估完工日期");
                            taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                            taskFlow.setCreateTime(new Date());

                            //判断是否因为逾期修改预估完工日期
                            if (ToolUtil.isNotEmpty(status.getNote())) {
//                                Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                //督导
                                String dd = openidMap.get("dd");
                                //营运经理
                                String yyjl = openidMap.get("yyjl");
                                Long role_yyzj = RoleIdEnum.ROLE_YYZJ.getCode();//营运总监
                                List<String> openidlist = userService.listOpenidsByRole(role_yyzj);
                                if (ToolUtil.isEmpty(openidlist)) {
                                    logger.error("未找到营运总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========营运总监:" + openidlist + "========");

                                Long role_gczj = RoleIdEnum.ROLE_GCZJ.getCode();//工程总监
                                List<String> gclist = userService.listOpenidsByRole(role_gczj);
                                if (ToolUtil.isEmpty(gclist)) {
                                    logger.error("未找到工程总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========工程总监:" + gclist + "========");

                                Long role_kfzj = RoleIdEnum.ROLE_KFZJ.getCode();//开发总监
                                List<String> kflist = userService.listOpenidsByRole(role_kfzj);
                                if (ToolUtil.isEmpty(kflist)) {
                                    logger.error("未找到开发总监微信openid,{}", BusExceptionEnum.NO_WX_ROLE);
//                                    throw new BusException(BusExceptionEnum.NO_WX_ROLE);
                                }
                                logger.info("=========开发总监:" + kflist + "========");

                                openidlist.remove(dd);
                                openidlist.add(dd);
                                openidlist.remove(yyjl);
                                openidlist.add(yyjl);
                                openidlist.removeAll(gclist);
                                openidlist.addAll(gclist);
                                openidlist.removeAll(kflist);
                                openidlist.addAll(kflist);

                                String[] openids = openidlist.toArray(new String[openidlist.size()]);

                                //查询店名
                                String dm = taskMapper.selectDm(status.getProId());

                                //查询开工时间
                                String con = taskMapper.selectCon(status.getProId(), 32).getContent();
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                                String dateSdf = sdf.format(new Date());//当前日期
                                Date date1 = null;
                                Date d1 = null;
                                long diffDays = 0;
                                Date wg = null;
                                long wgDays = 0;

                                try {
                                    date1 = sdf.parse(dateSdf);//当前日期
                                    d1 = sdf.parse(con);//开工时间
                                    String s = DateUtil.addDate(con, 28);//开工时间+28天(应该完工日期)
                                    wg = sdf.parse(s);

                                    //毫秒ms
                                    long diff = date1.getTime() - d1.getTime();//已开工时间
                                    diffDays = diff / (24 * 60 * 60 * 1000);//计算两个日期相差的时间

                                    //毫秒ms
                                    long diff1 = date1.getTime() - wg.getTime();//逾期时间
                                    wgDays = diff1 / (24 * 60 * 60 * 1000);//计算两个日期相差的时间
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }

//                                String data = dm + "已开工" + diffDays + "天,逾期" + wgDays + "天,逾期原因：" + status.getNote();
//                                JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "工程逾期", "工程逾期", DateUtil.getNow(), data);
//
//                                //推送消息
//                               //weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
//                                //logger.info("==========推送消息给督导,营运经理,营运总监,工程总监,开发总监=======");
                            }

                        } else {
                            //确认收银系统
                            if (status.getTaskId() == 21) {
                                if ("收银账号已建完，收银档案未建完".equals(status.getContent())) {
                                    //通知督导,设计
                                    String now = DateUtil.getNow();//当前时间
                                    //查询店名
                                    String dm = taskMapper.selectDm(status.getProId());
                                    String data = dm + "收银账号已建完";
                                    JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);
//                                    Map<String, String> openidMap = projectService.selectDd(status.getProId());
                                    //督导
                                    String dd = openidMap.get("dd");
                                    //设计(任召栋)
                                    String sj = BusConst.SJ;
                                    String[] openid = new String[]{sj};
//
//                                //推送消息
//                                //weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
//                                //logger.info("======已推送督导收银档案已建完消息======");

                                    //设计(任召栋)
                                    User user1 = btyWxMapper.selectUser(sj);

                                    if (ToolUtil.isNotEmpty(user1)){
                                        //收银系统url（设计）
                                        String sjUrl = BusConst.SYSJURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                        String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(sjUrl) + type + scope + state;
                                        //推送设计消息
//                                    weChatSendTempMsgService.sendmsg(openid, url1, tempObj);
//                                    logger.info("======已推送督导收银账号已建完消息======");
                                        pushList.add(new WxPushParamObj(openid, url1, tempObj));

                                        //消息表中新增收银系统消息
                                        GcgMsg gcgMsg = new GcgMsg();
                                        gcgMsg.setBusinessId(status.getProId());//业务id
                                        gcgMsg.setBusinessType("工程");//业务类型
                                        gcgMsg.setBusinessName(dm);//业务名称
                                        gcgMsg.setTaskId(status.getTaskId());//任务id
                                        gcgMsg.setMsgType("收银账号已建完");//消息类型
                                        gcgMsg.setMessage(data);//消息内容
                                        gcgMsg.setPath(url1);//跳转路径
                                        gcgMsg.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                        gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                        gcgMsg.setReceiveUser(user1.getUserId());//接收人ID
                                        gcgMsg.setCreateTime(new Date());//创建时间

                                        //消息表新增收银系统消息
                                        msgMapper.insert(gcgMsg);
                                    }

                                    List list = new ArrayList();
                                    list.add(dd);

                                    //接收消息人id
                                    List<User> userList = btyWxMapper.getUser(list);
                                    if (ToolUtil.isNotEmpty(userList)) {
                                        for (User user : userList) {
                                            //收银系统url（督导）
                                            String syUrl = BusConst.SYDDURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user.getUserId();
                                            String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;
                                            String[] openids = new String[]{user.getOpenid()};
                                            //推送消息
//                                            weChatSendTempMsgService.sendmsg(openids, url, tempObj);
//                                            logger.info("======已推送督导收银账号已建完消息======");
                                            pushList.add(new WxPushParamObj(openids, url, tempObj));

                                            //消息表中新增收银系统消息
                                            GcgMsg gcgMsg1 = new GcgMsg();
                                            gcgMsg1.setBusinessId(status.getProId());//业务id
                                            gcgMsg1.setBusinessType("工程");//业务类型
                                            gcgMsg1.setBusinessName(dm);//业务名称
                                            gcgMsg1.setTaskId(status.getTaskId());//任务id
                                            gcgMsg1.setMsgType("收银账号已建完");//消息类型
                                            gcgMsg1.setMessage(data);//消息内容
                                            gcgMsg1.setPath(url);//跳转路径
                                            gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                            gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());//发送人id(当前登录者id)
                                            gcgMsg1.setReceiveUser(user.getUserId());//接收人ID
                                            gcgMsg1.setCreateTime(new Date());//创建时间

                                            //消息表新增收银系统消息
                                            msgMapper.insert(gcgMsg1);
                                        }
                                    }


//                                //通知档案负责人
//                                String now = DateUtil.getNow();//当前时间
//                                //查询店名
//                                String dm = taskMapper.selectDm(status.getProId());
//                                String data = dm + "收银账号已建完";
//
//                                JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银账号已建完", "收银账号已建完", now, data);
//
//                                //韩铭渲
//                                String[] openids = new String[]{"oM18PwdQenG3H8Hf6dBZ-Wucz6c8"};
//
//                                //推送消息
//                                //weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
//                                //logger.info("======已推送档案负责人收银账号已建完消息======");

                                }

                            } else if (status.getContent() != null) {

                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                if (status.getStatus() != null) {
                                    taskFlow.setStatus(status.getStatus());//1提交；0审核未通过
                                } else {
                                    taskFlow.setStatus(1);
                                }
                                taskFlow.setTaskName(status.getTaskName());
                                taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                                taskFlow.setCreateTime(new Date());
                            }
                            //修改status表数据
                            taskMapper.updateCon(status);
                            //新增flow表数据
                            taskFlowMapper.add(taskFlow);
                        }
                    }


                } else {
                    //新增任务内容填写
                    if (status.getTaskName() != null) {
                        //查询该任务名称是否存在
                        int name = taskMapper.selectName(status.getTaskName());
                        //该工程中是否存在此名称
                        int taskName = taskMapper.selectTaskName(status.getTaskName(), status.getProId());
                        //该工程中没有填写此任务
                        if (taskName == 0) {
                            //名称不存在
                            if (name == 0) {
                                status.setStatus(1);//提交信息

                                taskStatuses.add(status);

                                //流程明细表
                                TaskFlow taskFlow = new TaskFlow();
                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                taskFlow.setStatus(1);//1提交；2审核未通过；3审核通过
                                if (status.getTaskName() != null || status.getTaskName() != "") {
                                    taskFlow.setTaskName(status.getTaskName());
                                }
                                taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                                taskFlow.setCreateTime(new Date());

                                taskFlows.add(taskFlow);

                            }
                        }
                    }
                }
            }
            int count1=0;
            int count2=0;
            if (taskStatuses.size()> 0) {
                //新增信息
                count1 = taskMapper.addRentList(taskStatuses);
            }

            if (taskFlows.size() >0) {
                //新增流程明细表
                count2 = taskFlowMapper.addList(taskFlows);
            }
            if(count1>0 && count2>0){
                //推送消息
                if(pushList.size()>0){
                    for(WxPushParamObj o:pushList){
                        weChatSendTempMsgService.sendmsg(o.getOpenids(),o.getJumpUrl(),o.getTempObj());
                    }
                }
            }
            return ResponseData.success();
    }


    /**
     * 收银系统修改状态
     *
     * @param taskStatus
     * @return
     */
    @Override
    public ResponseData cashierSave(TaskStatus taskStatus) {

        //修改状态,所有修改操作数据库新增条数必须都大于0才会提交事务
        StringBuilder result = new StringBuilder();
        // 数据库修改条数
        int count = 0;

        //流程明细表
        TaskFlow taskFlow = new TaskFlow();
        taskFlow.setProId(taskStatus.getProId());
        taskFlow.setTaskId(taskStatus.getTaskId());
        taskFlow.setStatus(1);//1提交；2审核未通过；3审核通过
        if (taskStatus.getTaskName() != null || taskStatus.getTaskName() != "") {
            taskFlow.setTaskName(taskStatus.getTaskName());
        }
        taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
        taskFlow.setCreateTime(new Date());

        //status表修改content
        count = taskMapper.updateCon(taskStatus);
        result.append(count > 0 ? 1 : 0);

        //flow表新增数据
        count = taskFlowMapper.add(taskFlow);
        result.append(count > 0 ? 1 : 0);

        //收银系统档案已建完
        if (taskStatus.getTaskId() == 21) {

            //通知档案负责人
            String now = DateUtil.getNow();//当前时间
            //查询店名
            String dm = taskMapper.selectDm(taskStatus.getProId());
            String data = dm + "收银档案已建完";

            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "收银档案已建完", "收银档案已建完", now, data);

            Map<String, String> openidMap = projectService.selectDd(taskStatus.getProId());
            //督导
            String dd = openidMap.get("dd");
            //设计/督导
            String[] openids = new String[]{BusConst.SJ, dd};

            //推送消息
            weChatSendTempMsgService.sendmsg(openids, BusConst.MSURL, tempObj);
            logger.info("======已推送督导,设计,收银档案已建完消息======");
        }

        if (result.indexOf("0") >= 0) {
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseData.error("修改失败");
        } else {
            return ResponseData.success();
        }

    }

    @Override
    public List<TaskResult> listIdsByRoleIds(String toleIds) {
        return baseMapper.listIdsByRoleIds(toleIds);
    }

    /**
     * 修改任务信息
     * @param taskStatus
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData editRent(List<TaskStatus> taskStatus) throws ParseException {

        //修改状态,所有修改操作数据库新增条数必须都大于0才会提交事务
        StringBuilder result = new StringBuilder();
        // 数据库修改条数
        int count = 0;

        if (ToolUtil.isNotEmpty(taskStatus)) {

            //任务状态
            List<TaskStatus> taskStatuses = new ArrayList<>();

            //任务流水
            List<TaskFlow> taskFlows = new ArrayList<>();

            for (TaskStatus status : taskStatus) {
                long userId = 0;
                //APP端传用户电话
                if(ToolUtil.isNotEmpty(status.getAccount())){
                    userId = userMapper.getUserId(status.getAccount());
                }

                //填写内容为固定项
                if (status.getTaskId() != null) {

                    //查询该工程该项是否已经填写信息
                    int msg = taskMapper.getCount(status.getProId(), status.getTaskId());
                    //之前填写过信息
                    if (msg != 0) {

                        //配送要货
                        if (status.getTaskId() != 15){
                            if (status.getStatus() == null) {
                                status.setStatus(1);//提交信息
                            }

                            taskStatuses.add(status);

                            //流程明细表
                            TaskFlow taskFlow = new TaskFlow();
                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(status.getTaskId());

                            if (status.getStatus() != null) {
                                taskFlow.setStatus(status.getStatus());
                            } else {
                                taskFlow.setStatus(1);
                            }

                            if (status.getTaskName() != null || status.getTaskName() != "") {
                                taskFlow.setTaskName(status.getTaskName());
                            }
                            if (ToolUtil.isNotEmpty(status.getCreateId())){
                                taskFlow.setCreateUser(status.getCreateId());
                            }else if (userId != 0){
                                taskFlow.setCreateUser(userId);
                            }else {
                                taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                            }
                            taskFlow.setCreateTime(new Date());

                            taskFlows.add(taskFlow);
                        }




//                            //预估完工日期
//                        if (status.getTaskId() == 33) {
//
//                            TaskStatus status1 = new TaskStatus();
//                            //预估开业时间
//                            status1.setTaskId(22);
//                            //预估完工日期+7天
//                            status1.setContent(DateUtil.addDate(status.getContent(), 7));
//                            status1.setProId(status.getProId());
//                            status1.setStatus(1);
//                            status1.setTaskName("预估开业时间");
//
//                            taskStatuses.add(status1);
//
//                            //流程明细表
//                            TaskFlow taskFlow1 = new TaskFlow();
//                            taskFlow1.setProId(status.getProId());
//                            taskFlow1.setTaskId(22);
//                            taskFlow1.setStatus(1);//1提交；0审核未通过
//                            taskFlow1.setTaskName("预估开业时间");
//                            if (ToolUtil.isNotEmpty(status.getCreateId())) {
//                                taskFlow1.setCreateUser(status.getCreateId());
//                            }else {
//                                taskFlow1.setCreateUser(LoginContextHolder.getContext().getUserId());
//                            }
//                            taskFlow1.setCreateTime(new Date());
//
//                            taskFlows.add(taskFlow1);
//
//                        }
                        //营业执照名称
                         if(status.getTaskId() == 56 && ToolUtil.isNotEmpty(status.getContent())){
                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());
                            if(ToolUtil.isNotEmpty(yaoma)){
                                BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                if(ToolUtil.isNotEmpty(txl)){
                                    txl.setYyzzmc(status.getContent());
                                    btyTxlService.updateById(txl);
                                }
                            }

                        }
                        //统一社会信用代码
                        else if(status.getTaskId() == 57 && ToolUtil.isNotEmpty(status.getContent())){
                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());
                            if(ToolUtil.isNotEmpty(yaoma)){
                                BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                if(ToolUtil.isNotEmpty(txl)){
                                    txl.setShxydm(status.getContent());
                                    btyTxlService.updateById(txl);
                                }
                            }
                        }

                         //法人姓名 更新到双证审核中
                         else if(status.getTaskId() == 59 && ToolUtil.isNotEmpty(status.getContent())){
                             BtyDoubleCard doubleCard=doubleCardService.getOne(new QueryWrapper<BtyDoubleCard>().eq("pro_id",status.getProId()));
                             if(ToolUtil.isNotEmpty(doubleCard)){
                                 doubleCard.setFrxm(status.getContent());
                                 doubleCardService.updateById(doubleCard);
                             }
                         }

                        //确定工程开业日期
                        if (status.getTaskId() == 16) {

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            Date toDate = sdf.parse(status.getContent());//开业日期

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setOpenDate(toDate);//开业日期
                            projectParam.setId(status.getProId());

                            //修改工程开业时间
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已修改开业时间========");

                            //收银系统负责人 (刘书伟)
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");
                            String dm = taskMapper.selectDm(status.getProId());

                            //推送收银系统确认消息
                            String data = dm + "已修改开业日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;
                            logger.info("==========开业时间已修改========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成

                                //当前登录者id
                                if (ToolUtil.isNotEmpty(status.getCreateId())) {
                                    gcgMsg.setSendUser(status.getCreateId());
                                }else if (userId != 0){
                                    gcgMsg.setSendUser(userId);
                                }else {
                                    gcgMsg.setSendUser(LoginContextHolder.getContext().getUserId());
                                }

                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            String data1 = dm + "已修改开业日期为:" + status.getContent() + "。该店督导为：" + ddName + "电话为:" + ddTel;
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认开业日期", "开业日期", DateUtil.getNow(), data1);

                            //设计总监(朱小平)
                            String sjzj = BusConst.SJZJ;
                            String[] openids1 = new String[]{sjzj};


                            //设计总监(朱小平)id
                            User user1 = btyWxMapper.selectUser(sjzj);

                            if (ToolUtil.isNotEmpty(user1)){
                                //确定开业日期url（已确认）
                                String kyUrl = BusConst.KYURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kyUrl) + type + scope + state;

                                //推送设计总监消息
                                weChatSendTempMsgService.sendmsg(openids1, url1, tempObj1);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(status.getTaskId());//任务id
                                gcgMsg1.setMsgType("修改开业日期提醒");//消息类型
                                gcgMsg1.setMessage(data1);//消息内容
                                gcgMsg1.setPath(url1);//跳转路径
                                gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成

                                //当前登录者id
                                if (ToolUtil.isNotEmpty(status.getCreateId())) {
                                    gcgMsg1.setSendUser(status.getCreateId());
                                }else if (userId != 0){
                                    gcgMsg1.setSendUser(userId);
                                }else {
                                    gcgMsg1.setSendUser(LoginContextHolder.getContext().getUserId());
                                }

                                gcgMsg1.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg1);
                            }
                            //丁玲
                            String dl = BusConst.DL;
                            String[] openid = new String[]{dl};
                            //丁玲id
                            User userDl = btyWxMapper.selectUser(dl);

                            if (ToolUtil.isNotEmpty(userDl)){
                                //推送丁玲消息
                                weChatSendTempMsgService.sendmsg(openid, BusConst.MSURL, tempObj1);
                                logger.info("=======推送丁玲消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
                                gcgMsg2.setTaskId(status.getTaskId());//任务id
                                gcgMsg2.setMsgType("修改开业日期提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setPath(BusConst.MSURL);//跳转路径
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成

                                //当前登录者id
                                if (ToolUtil.isNotEmpty(status.getCreateId())) {
                                    gcgMsg2.setSendUser(status.getCreateId());
                                }else if (userId != 0){
                                    gcgMsg2.setSendUser(userId);
                                }else {
                                    gcgMsg2.setSendUser(LoginContextHolder.getContext().getUserId());
                                }

                                gcgMsg2.setReceiveUser(userDl.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg2);
                            }

                            //到货日期（配送要货）
                        }else if (status.getTaskId() == 15 && ToolUtil.isNotEmpty(status.getContent())){

                            boolean convertSuccess = true;
                            try {
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                Date toDate = sdf.parse(status.getContent());//到货日期
                            }catch (Exception e){
                                convertSuccess = false;
                                e.printStackTrace();
                            }

                            if (convertSuccess){
                                status.setStatus(0);//待发货
                                taskStatuses.add(status);

                                //流程明细表
                                TaskFlow taskFlow = new TaskFlow();
                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                taskFlow.setStatus(0);
                                if (status.getTaskName() != null || status.getTaskName() != "") {
                                    taskFlow.setTaskName(status.getTaskName());
                                }
                                if (ToolUtil.isNotEmpty(status.getCreateId())){
                                    taskFlow.setCreateUser(status.getCreateId());
                                }else if (userId != 0){
                                    taskFlow.setCreateUser(userId);
                                }else {
                                    taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                                }
                                taskFlow.setCreateTime(new Date());

                                taskFlows.add(taskFlow);

//                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//                            Date toDate = sdf.parse(status.getContent());//到货日期

                                //工程表
                                ProjectParam projectParam = new ProjectParam();
                                projectParam.setArrivalTime(status.getContent());//预计到货日期
                                projectParam.setId(status.getProId());
                                projectParam.setPsStatus("0");//待发货

                                //修改工程到货日期
                                projectMapper.updateProjectByCondition(projectParam);
                                logger.info("===========工程表已修改到货日期========");
                            }


                            //确认到货
                        }else if (status.getTaskId() == 15 && ToolUtil.isEmpty(status.getContent())){
                            status.setStatus(2);//已到货
                            taskStatuses.add(status);

                            //流程明细表
                            TaskFlow taskFlow = new TaskFlow();
                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(status.getTaskId());
                            taskFlow.setStatus(2);
                            if (status.getTaskName() != null || status.getTaskName() != "") {
                                taskFlow.setTaskName(status.getTaskName());
                            }
                            if (ToolUtil.isNotEmpty(status.getCreateId())){
                                taskFlow.setCreateUser(status.getCreateId());
                            }else if (userId != 0){
                                taskFlow.setCreateUser(userId);
                            }else {
                                taskFlow.setCreateUser(LoginContextHolder.getContext().getUserId());
                            }
                            taskFlow.setCreateTime(new Date());

                            taskFlows.add(taskFlow);

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            String toDate = sdf.format(new Date());

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setDhTime(toDate);//实际到货日期
                            projectParam.setId(status.getProId());
                            projectParam.setPsStatus("2");//已到货

                            //修改工程实际到货日期
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已修改到货日期========");
                        }
                        //卫生许可证
                        else if (status.getTaskId() == 44) {

                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());

                            //通讯录同步食品经营许可证数据
                            BtyTxl btyTxl = new BtyTxl();
                            btyTxl.setSpjyxk(status.getContent());//食品经营许可证
                            btyTxl.setCtbh(yaoma);//妖码
                            btyTxlService.edit(btyTxl);
                        }



                    }
                }
            }



            if (taskStatuses.size() != 0) {
                //修改信息
                count = taskMapper.editRentList(taskStatuses);
                result.append(count > 0 ? 1 : 0);
            }

            if (taskFlows.size() != 0) {
                //新增流程明细表
                count = taskFlowMapper.addList(taskFlows);
                result.append(count > 0 ? 1 : 0);
            }

        }
        if (result.indexOf("0") >= 0) {
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseData.error("添加失败");
        } else {
            return ResponseData.success();
        }

    }

    /**
     * 修改任务信息
     * @param taskStatus
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData editRentH5(List<TaskStatus> taskStatus,Long userId) throws ParseException {

        //修改状态,所有修改操作数据库新增条数必须都大于0才会提交事务
        StringBuilder result = new StringBuilder();
        // 数据库修改条数
        int count = 0;

        if (ToolUtil.isNotEmpty(taskStatus)) {

            //任务状态
            List<TaskStatus> taskStatuses = new ArrayList<>();
            //任务流水
            List<TaskFlow> taskFlows = new ArrayList<>();

            for (TaskStatus status : taskStatus) {

                //填写内容为固定项
                if (status.getTaskId() != null) {

                    //查询该工程该项是否已经填写信息
                    int msg = taskMapper.getCount(status.getProId(), status.getTaskId());

                    //之前填写过信息
                    if (msg != 0) {

                        //配送要货
                        if (status.getTaskId() != 15){
                            if (status.getStatus() == null) {
                                status.setStatus(1);//提交信息
                            }

                            taskStatuses.add(status);

                            //流程明细表
                            TaskFlow taskFlow = new TaskFlow();
                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(status.getTaskId());

                            if (status.getStatus() != null) {
                                taskFlow.setStatus(status.getStatus());
                            } else {
                                taskFlow.setStatus(1);
                            }

                            if (status.getTaskName() != null || status.getTaskName() != "") {
                                taskFlow.setTaskName(status.getTaskName());
                            }
                            if (ToolUtil.isNotEmpty(status.getCreateId())){
                                taskFlow.setCreateUser(status.getCreateId());
                            }else {
                                taskFlow.setCreateUser(userId);
                            }
                            taskFlow.setCreateTime(new Date());

                            taskFlows.add(taskFlow);
                        }

                        //确定工程开业日期
                        if (status.getTaskId() == 16) {

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            Date toDate = sdf.parse(status.getContent());//开业日期

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setOpenDate(toDate);//开业日期
                            projectParam.setId(status.getProId());

                            //修改工程开业时间
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已修改开业时间========");

                            //收银系统负责人 (刘书伟)
                            String syxt = BusConst.LSW;
                            String[] openids = new String[]{syxt};

                            //收银系统负责人 (刘书伟)id
                            User user = btyWxMapper.selectUser(syxt);
                            Map<String, String> openidMap = projectService.selectDd(status.getProId());

                            String ddName = openidMap.get("ddName");
                            String ddTel = openidMap.get("ddTel");
                            String dm = taskMapper.selectDm(status.getProId());

                            //推送收银系统确认消息
                            String data = dm + "已修改开业日期为:" + status.getContent() + ",请确认收银系统。该店督导为：" + ddName + "电话为:" + ddTel;
                            logger.info("==========开业时间已修改========");

                            JSONObject tempObj = weChatSendTempMsgService.setTempParam(dm, null, "确认收银系统", "收银系统", DateUtil.getNow(), data);

                            if (ToolUtil.isNotEmpty(user)){
                                //收银系统url（负责人）
                                String syUrl = BusConst.SYURL + "&proId=" + status.getProId() + "&taskId=21" + "&userId=" + user.getUserId();
                                String url = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(syUrl) + type + scope + state;

                                //推送收银系统消息
                                weChatSendTempMsgService.sendmsg(openids, url, tempObj);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增收银系统消息
                                GcgMsg gcgMsg = new GcgMsg();
                                gcgMsg.setBusinessId(status.getProId());//业务id
                                gcgMsg.setBusinessType("工程");//业务类型
                                gcgMsg.setBusinessName(dm);//业务名称
                                gcgMsg.setTaskId(21);//任务id
                                gcgMsg.setMsgType("确认收银系统提醒");//消息类型
                                gcgMsg.setMessage(data);//消息内容
                                gcgMsg.setPath(url);//跳转路径
                                gcgMsg.setTaskStatus(1);//任务状态;0->已完成，1->未完成
                                gcgMsg.setSendUser(userId);//当前登录者id
                                gcgMsg.setReceiveUser(user.getUserId());//接收人ID
                                gcgMsg.setCreateTime(new Date());//创建时间

                                //消息表新增收银系统数据
                                msgMapper.insert(gcgMsg);
                            }

                            String data1 = dm + "已修改开业日期为:" + status.getContent() + "。该店督导为：" + ddName + "电话为:" + ddTel;
                            JSONObject tempObj1 = weChatSendTempMsgService.setTempParam(dm, null, "确认开业日期", "开业日期", DateUtil.getNow(), data1);

                            //设计总监(朱小平)
                            String sjzj = BusConst.SJZJ;
                            String[] openids1 = new String[]{sjzj};


                            //设计总监(朱小平)id
                            User user1 = btyWxMapper.selectUser(sjzj);

                            if (ToolUtil.isNotEmpty(user1)){
                                //确定开业日期url（已确认）
                                String kyUrl = BusConst.KYURL + "&proId=" + status.getProId() + "&taskId=" + status.getTaskId() + "&userId=" + user1.getUserId();
                                String url1 = path + gzhConfig.getAppid() + "&redirect_uri=" + URLEncoder.encode(kyUrl) + type + scope + state;

                                //推送设计总监消息
                                weChatSendTempMsgService.sendmsg(openids1, url1, tempObj1);
                                logger.info("=======推送收银系统负责人消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg1 = new GcgMsg();
                                gcgMsg1.setBusinessId(status.getProId());//业务id
                                gcgMsg1.setBusinessType("工程");//业务类型
                                gcgMsg1.setBusinessName(dm);//业务名称
                                gcgMsg1.setTaskId(status.getTaskId());//任务id
                                gcgMsg1.setMsgType("修改开业日期提醒");//消息类型
                                gcgMsg1.setMessage(data1);//消息内容
                                gcgMsg1.setPath(url1);//跳转路径
                                gcgMsg1.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg1.setSendUser(userId);//当前登录者id
                                gcgMsg1.setReceiveUser(user1.getUserId());//接收人ID
                                gcgMsg1.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg1);
                            }
                            //丁玲
                            String dl = BusConst.DL;
                            String[] openid = new String[]{dl};
                            //丁玲id
                            User userDl = btyWxMapper.selectUser(dl);

                            if (ToolUtil.isNotEmpty(userDl)){
                                //推送丁玲消息
                                weChatSendTempMsgService.sendmsg(openid, BusConst.MSURL, tempObj1);
                                logger.info("=======推送丁玲消息==========");

                                //消息表中新增确认开业时间消息
                                GcgMsg gcgMsg2 = new GcgMsg();
                                gcgMsg2.setBusinessId(status.getProId());//业务id
                                gcgMsg2.setBusinessType("工程");//业务类型
                                gcgMsg2.setBusinessName(dm);//业务名称
                                gcgMsg2.setTaskId(status.getTaskId());//任务id
                                gcgMsg2.setMsgType("修改开业日期提醒");//消息类型
                                gcgMsg2.setMessage(data1);//消息内容
                                gcgMsg2.setPath(BusConst.MSURL);//跳转路径
                                gcgMsg2.setTaskStatus(0);//任务状态;0->已完成，1->未完成
                                gcgMsg2.setSendUser(userId);//当前登录者id
                                gcgMsg2.setReceiveUser(userDl.getUserId());//接收人ID
                                gcgMsg2.setCreateTime(new Date());//创建时间

                                //消息表新增收确认开业时间消息
                                msgMapper.insert(gcgMsg2);
                            }

                            //到货日期（配送要货）
                        }else if (status.getTaskId() == 15 && ToolUtil.isNotEmpty(status.getContent())){

                            boolean convertSuccess = true;
                            try {
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                Date toDate = sdf.parse(status.getContent());//到货日期
                            }catch (Exception e){
                                convertSuccess = false;
                                e.printStackTrace();
                            }

                            if (convertSuccess){
                                status.setStatus(0);//待发货
                                taskStatuses.add(status);

                                //流程明细表
                                TaskFlow taskFlow = new TaskFlow();
                                taskFlow.setProId(status.getProId());
                                taskFlow.setTaskId(status.getTaskId());
                                taskFlow.setStatus(0);
                                if (status.getTaskName() != null || status.getTaskName() != "") {
                                    taskFlow.setTaskName(status.getTaskName());
                                }
                                if (ToolUtil.isNotEmpty(status.getCreateId())){
                                    taskFlow.setCreateUser(status.getCreateId());
                                }else {
                                    taskFlow.setCreateUser(userId);
                                }
                                taskFlow.setCreateTime(new Date());

                                taskFlows.add(taskFlow);

                                //工程表
                                ProjectParam projectParam = new ProjectParam();
                                projectParam.setArrivalTime(status.getContent());//预计到货日期
                                projectParam.setId(status.getProId());
                                projectParam.setPsStatus("0");//待发货

                                //修改工程到货日期
                                projectMapper.updateProjectByCondition(projectParam);
                                logger.info("===========工程表已修改到货日期========");
                            }


                            //确认到货
                        }else if (status.getTaskId() == 15 && ToolUtil.isEmpty(status.getContent())){
                            status.setStatus(2);//已到货
                            taskStatuses.add(status);

                            //流程明细表
                            TaskFlow taskFlow = new TaskFlow();
                            taskFlow.setProId(status.getProId());
                            taskFlow.setTaskId(status.getTaskId());
                            taskFlow.setStatus(2);
                            if (status.getTaskName() != null || status.getTaskName() != "") {
                                taskFlow.setTaskName(status.getTaskName());
                            }
                            if (ToolUtil.isNotEmpty(status.getCreateId())){
                                taskFlow.setCreateUser(status.getCreateId());
                            }else {
                                taskFlow.setCreateUser(userId);
                            }
                            taskFlow.setCreateTime(new Date());

                            taskFlows.add(taskFlow);

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            String toDate = sdf.format(new Date());

                            //工程表
                            ProjectParam projectParam = new ProjectParam();
                            projectParam.setDhTime(toDate);//实际到货日期
                            projectParam.setId(status.getProId());
                            projectParam.setPsStatus("2");//已到货

                            //修改工程实际到货日期
                            projectMapper.updateProjectByCondition(projectParam);
                            logger.info("===========工程表已修改到货日期========");
                        }
                        //卫生许可证
                        else if (status.getTaskId() == 44) {

                            addTxl(status.getProId(), status.getContent(), status.getTaskId());

//                            //获取妖码
//                            String yaoma = projectMapper.getYm(status.getProId());
//
//                            //通讯录同步食品经营许可证数据
//                            BtyTxl btyTxl = new BtyTxl();
//                            btyTxl.setSpjyxk(status.getContent());//食品经营许可证
//                            btyTxl.setCtbh(yaoma);//妖码
//                            btyTxlService.edit(btyTxl);
                        }
                        //营业执照名称
                         if(status.getTaskId() == 56 && ToolUtil.isEmpty(status.getContent())){
                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());
                            if(ToolUtil.isNotEmpty(yaoma)){
                                BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                if(ToolUtil.isNotEmpty(txl)){
                                   txl.setYyzzmc(status.getContent());
                                    btyTxlService.updateById(txl);
                                }
                            }

                        }
                        //统一社会信用代码
                        else if(status.getTaskId() == 57 && ToolUtil.isEmpty(status.getContent())){
                            //获取妖码
                            String yaoma = projectMapper.getYm(status.getProId());
                            if(ToolUtil.isNotEmpty(yaoma)){
                                BtyTxl txl=btyTxlService.getOne(new QueryWrapper<BtyTxl>().eq("ctbh",yaoma));
                                if(ToolUtil.isNotEmpty(txl)){
                                    txl.setShxydm(status.getContent());
                                    btyTxlService.updateById(txl);
                                }
                            }
                        }

                    }

                }
            }

            if (taskStatuses.size() != 0) {
                //修改信息
                count = taskMapper.editRentList(taskStatuses);
                result.append(count > 0 ? 1 : 0);
            }

            if (taskFlows.size() != 0) {
                //新增流程明细表
                count = taskFlowMapper.addList(taskFlows);
                result.append(count > 0 ? 1 : 0);
            }

        }
        if (result.indexOf("0") >= 0) {
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseData.error("添加失败");
        } else {
            return ResponseData.success();
        }

    }


    /**
     * 同步通讯录数据
     */
    @Transactional(rollbackFor = Exception.class)
    public void addTxl(Integer proId, String content, Integer taskId){

        //查询该工程的城市,营运经理,开业时间
        Project project = projectMapper.selectProject(proId);

        if (ToolUtil.isNotEmpty(project)) {

            String btyDm = project.getName();
            //店名（截取省之后的字符）
            if (btyDm.contains("省") || btyDm.contains("自治区")){
                if (!project.getProvinceName().equals("北京") && !project.getProvinceName().equals("天津")
                        && !project.getProvinceName().equals("上海") && !project.getProvinceName().equals("重庆")) {

                    btyDm = project.getName().split(project.getProvinceName())[1].replaceAll("\\s*", "");
                }
            }

            //妖码
            String yaoma = project.getYaoma();

            //查询表中是否存在该数据
            int count = btyTxlMapper.getTxlByDm(btyDm);

            int con = btyTxlMapper.getTxlByYm(yaoma);

            //通讯录新增数据
            BtyTxl btyTxl = new BtyTxl();
            btyTxl.setCsqy(project.getProvinceName());//城市区域
            btyTxl.setYyjlqy(project.getYyjlName());//营运经理
            btyTxl.setDm(btyDm);//店名
            btyTxl.setKysj(project.getOpenTime());//开业时间
            btyTxl.setCtdz(project.getRestAddress());//餐厅地址
            btyTxl.setCtbh(yaoma);//妖码

            //卫生许可证年审日期
            if (taskId == 44){
                //通讯录同步食品经营许可证数据
                btyTxl.setSpjyxk(content);//食品经营许可证
            }

            //不存在该数据
            if (count == 0 && con == 0){
                btyTxlService.addct(btyTxl);

                ///存在妖码
            }else if (count == 0 && con != 0){
                btyTxlMapper.updateCtByYm(btyTxl);

                //存在店名
            }else {
                btyTxlMapper.updateCtByDm(btyTxl);
            }

            //查询表中是否存在该数据
            int ddCount = btyTxlMapper.selectCount(btyDm, "督导");

            //bty_txl_ry表新增数据
            BtyTxlRY btyTxlRY = new BtyTxlRY();
            btyTxlRY.setZw("督导");//职务(督导)
            btyTxlRY.setFzr(project.getDdName());//负责人
            btyTxlRY.setLxfs(project.getDdTel());//联系方式
            btyTxlRY.setSsctdm(btyDm);//店名

            //不存在该数据
            if (ddCount == 0) {
                btyTxlMapper.addfzr(btyTxlRY);
            } else {
                btyTxlMapper.updateTxlRY(btyTxlRY);
            }

            //查询表中是否存在该数据
            int dzCount = btyTxlMapper.selectCount(btyDm, "店长");

            //bty_txl_ry表新增数据
            BtyTxlRY btyTxlRY1 = new BtyTxlRY();
            btyTxlRY1.setZw("店长");//职务(店长)
            btyTxlRY1.setFzr(project.getDz());//负责人
            btyTxlRY1.setLxfs(project.getDzTel());//联系方式
            btyTxlRY1.setSsctdm(btyDm);//店名

            //不存在该数据
            if (dzCount == 0) {
                btyTxlMapper.addfzr(btyTxlRY1);
            } else {
                btyTxlMapper.updateTxlRY(btyTxlRY1);
            }

            //btyy_region表新增数据
            BtyRegion btyRegion = new BtyRegion();
            btyRegion.setYyjl(project.getYyjlName());//营运经理
            btyRegion.setDm(btyDm);//店名
            btyRegion.setDd(project.getDdName());//督导
            btyRegion.setDz(project.getDz());//店长
            btyRegion.setCreateTime(new Date());
            this.regionMapper.insert(btyRegion);
        }

    }


    /**
     * 同步brand表数据
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addBrand(Integer proId){

        //查询该工程的妖码，店名
        Project project = projectMapper.getPro(proId);

        if (ToolUtil.isNotEmpty(project)) {

            //店名
            String btyDm = project.getName();
            //妖码
            String yaoma = project.getYaoma();

            //brand表新增数据
            BtyBrand brand = new BtyBrand();
            brand.setBh(yaoma);//编号
            brand.setDm(btyDm);//店名
            brand.setYaoma(yaoma);//妖码
            btyBrandMapper.addBrand(brand);

            //brankyeb表新增数据
            BtyBankyebDto btyBankyebDto = new BtyBankyebDto();
            btyBankyebDto.setBh(yaoma);
            btyBankyebDto.setDm(btyDm);
            btyBrandMapper.addYeb(btyBankyebDto);
        }

    }


}
